how can I send PHP parametres, get method like .php?id=xx
I am using K2 items with Joomla. Currently I am printing out all results fetched from database using PHP. When user clicks on one of the results it should send him to different page and that page should get id of the thing user clicked. How do I do it if joomla shows me sites like:
joomla.com/index.php/example-showing-this/
This is a very broad question, and we'd more details to better help you. On a broad level, you can generate these URLs using PHP and JRoute http://docs.joomla.org/JRoute/1.5
You may also find this thread helpful too https://groups.google.com/forum/?fromgroups#!topic/joomla-dev-general/1548yu9I2jQ
When the user is able to click on things this is no longer PHP, this is HTML and javascript. PHP is executed on the server, the result of this execution is the HTML+CSS+Javascript that the user downloads to its pc.
From what you descrived you need to generate the correct HTML+javascript using the PHP variables you get from the database, for example:
echo "Click me";
This will display a link, but it will not pass any parameters, if you want to pass a id using GET you should do it like this:
$id=1234;
echo "Click me";
In the your_php_page.php you can receive this id like this:
$id=$_GET['id'];
//if you are going to use this in a query you should do something like this to prevent injection
$id=$mysqli->real_escape_string($id);
If you want to use POST, you will have to submit a form or use AJAX, but that's more advanced, you should focus on making it work using GET.
Related
Question about GET and POST in PHP. i wonder what is the difference between POST and GET and when do you use them respectively?
so as far from i tried, GET can also show the data in the link.
for example, the name of my link is Localhost/index.php then inside my php file is an input box and a submit button. if for example i use GET, if i click the submit button, it will take the data i put in inputbox(for example, name) and add it to the link. so the link now is Localhost/index.php/?name=Tina i think this is how GET works. but if i use POST, it will not show the input data in the link and it will remain Localhost/index.php. (atleast, from what i practice)
i wonder what are other differences between the two and when they should be use? for example im making a website(ex: sign up website) that will take information and send it to a database in MySQL..or the webpage should carry over the from this webpage to another webpage. should i use GET or POST?
You are kind of overthinking it. It is as simple as:
POST - used to post(send) data to the database.
GET - used to get(fetch) data from the database.
So in the case of the form, what you need to do is a POST request, so you send the data to MySQL. And in order to retrieve that data, you will perform a GET request.
See this https://www.geeksforgeeks.org/http-get-post-methods-php/ for a comprehensive explanation.
Keeping it very short:
You never-ever should pass any sensitive information over GET method, because it's visible by logs, by your internet provider/router, third parties.. such as google analytics and more.
A common use of GET is when you allow users to change the parameters of a page they see.. i.e. search parameters or the number of products per page.
POST when you want to send information to the server "privately" and (preferably) with a nonce to make it sendable only once.
But regardless of a method - POST or GET - sanitise, sanitise, sanitise.. that is what you need to really worry about. User input should not be accepted as is when you receive it, kinda #1 rule on the internet.
I'm currently only using PHP to take user submissions, put them in a database, and echo them out on a page using SQL to select from a table, such as comments. I need a system that will automatically update comments without refreshing the page like on YouTube. The less the user has to manually update, the better.
I want it to work pretty much exactly how YouTube and Twitter function, where it'll say "x NEW COMMENT(s)" and clicking that updates everything.
My teacher recommended a JQuery function, but I don't have any background in that language so I don't know where to begin looking.
I'm at a complete impasse. I will update this if you guys need additional information to aid in my search.
You are looking for AJAX
You will need a HTML page with jQuery/AJAX that calls another PHP page. In that PHP page you do the DB request and then ideally return the data as JSON so that your frontend part can display it to the user.
As every one says, AJAX is the way. You can find a simple blog I did on it here.
I'm hoping someone can help me. I am trying to just pass a variable from one page to another in my jQuery mobile website, which you can see here: http://www.muskermcintyre.co.uk/tablet.
The usual way I would do this is the following:
To have a link on the list view page which looks something like this:
View details
Then I would need to use $_GET['profileID'] on my full details page, to get the correct property from the database, obviously just getting that profileID which has been passed from the link on the previous page. It seems this is not possible in jQuery mobile.
Please can anyone suggest the best way to do this?
Thanks!
You can use the same method for your JavaScript as in PHP, the only difference is that you don't have the query string variables as an array named $_GET, you have to parse them yourself. See this answer:
How can I get query string values in JavaScript?
PHP is a server side scripting language.
Once your page is loaded (i.e HTML is generated). You will have to use either JavaScript or JQuery.Or you will have to post back to server to render new HTML.
I currently have 2 pages:
Follow.php:a PHP page which is all setup with twitters api and will follow any user on twitter with the specific parameter you put in.
One index.php page, which has a list of links of people you can follow.
What I am looking to do is have it so when a user clicks on one of the people to follow on index.php, the variable in follow.php (which is used as a parameter and is the username of twitter account that is going to be followed) gets set to the name attribute of the link selected.
Now I am not the greatest developer, so I am not sure of the best way of doing this. There is probably a better way of doing it that what I am thinking of. I was thinking of using jquery to say something like:
$('a').click(function(){
<?php $group=?>$(this).attr('name'); //trying to set a php variable to name attr
})
This was going to be in its own new file,
then I was going to include this script into the follow.php script and use the variable. This is not working, unsurprisingly. I hope I explained what I was trying to do well.
So I have two questions.
Number 1:what is the best way of achieving what I am trying to do? can i do this all in php?
Number 2: is it possible to do what I was trying to do with jquery and setting the php var equal to the name attr?
PHP runs on the server. JavaScript (jQuery) runs on the browser. PHP can be used to write JS, but JS can't affect PHP (except via AJAX or similar).
What you need to do is do a POST on the Follow.php page and accept the username value. This is a great resource for that: http://www.html.net/tutorials/php/lesson10.php
You can simply set the link href for each tag on the index page to go got Follow.php?user=twitterHandle (where twitterHandle is the twitter username of a person). This way, you dont need to use any javascript at all.
I'm trying to implement a Facebook connect button to my website.
It's working, but it's written in JavaScript and I'd like to insert the information into the database (the tutorial I used is linked below.)
I'm trying to redirect the users from the index.php to index.php?name=xxx.
The name value is rendered with JavaScript so I can't simply just set a PHP variable, can I?
I've been told it's possible with $_GET so that's what I'm trying to achieve.
Using location.href/replace, both redirect to the same page over and over again...
This is the tutorial I used.
I would like to store some information in the database, but I can't do it directly since it's JavaScript and not PHP.
Is there a solution/any other way?
check if the name parameter is filled or not, and if it is, do not redirect