...

View Full Version : Confusion when passing variables through urls...



inVINCEable
06-08-2007, 10:51 PM
I just created a script that allows me to update values in my database with the help of a friend. I understand everything perfectly except this first part of the update script, and a variable it utilizes, called ['id]. Here is the first part of the script...




if ((isset($_GET['id'])) && (is_numeric($_GET['id']))) {
$id = $_GET['id'];
}


Now I understand what it does, I just do not understand where this 'id' variable is coming from since I have not defined any id variable throughout my scripts on this project.

My guess is it is coming through this part of my code:



<td><a href="edit_user.php?id=' .$row['user_id'] .'">Edit</a></td>


So am I setting a variable here when I use the ?id= in the above code?


So if I renamed this to:



<td><a href="edit_user.php?alternativevariable=' .$row['user_id'] .'">Edit</a></td>



If I renamed it then my new variable would be ['alternativevariable'] ?


Any guidance or help is greatly appreciated because I just do not understand where this ['id] variable is coming from.



Thanks.


Then my

mlseim
06-08-2007, 11:28 PM
Say your page has this:
<td><a href="edit_user.php?alternativevariable=test123&action=edit">Edit</a></td>
<td><a href="edit_user.php?alternativevariable=test123&action=delete">Delete</a></td>

Your script has this:
<?php
$myid = $_GET['alternativevariable'];
$action = $_GET['action'];

if you echo the two:
$myid would be: "test123"
and $action would be: "delete" or "edit", depending on which link you clicked.

You'll notice how the variable called "alternativevariable" is loaded
into another variable called $myid once it gets into the script.
You don't have to do that .. example $action is the same name.

The other part, isset($_GET ..... , is testing to see if the variable has
been set (if the variable is null ... no character, it's not set).

I hope I don't confuse you ... you can look this stuff up on Google too.

inVINCEable
06-09-2007, 12:21 AM
Say your page has this:
<td><a href="edit_user.php?alternativevariable=test123&action=edit">Edit</a></td>
<td><a href="edit_user.php?alternativevariable=test123&action=delete">Delete</a></td>

Your script has this:
<?php
$myid = $_GET['alternativevariable'];
$action = $_GET['action'];

if you echo the two:
$myid would be: "test123"
and $action would be: "delete" or "edit", depending on which link you clicked.

You'll notice how the variable called "alternativevariable" is loaded
into another variable called $myid once it gets into the script.
You don't have to do that .. example $action is the same name.

The other part, isset($_GET ..... , is testing to see if the variable has
been set (if the variable is null ... no character, it's not set).

I hope I don't confuse you ... you can look this stuff up on Google too.



Thank you for taking the time to right that. Now I am 99% sure I understand what you are saying.

You are saying that you can se the variable name after whatever you want as long as you set the href link to use an '=' sign. So if I wanted to add another variable I would set it like this...



<td><a href="edit_user.php?alternativevariable=test123&action=edit&thirdvariable=echothis">Edit</a></td>


$third = $_GET['thirdvariable]


And if I echoed $third to my screen, the output would be "echothis"?


Thanks again.

whizard
06-09-2007, 04:55 AM
Yes

You can append unlimited variables to the URL

http://www.mysite.com?var=a&var2=b&var3=c&var4=etc

HTH
Dan

inVINCEable
06-09-2007, 07:37 AM
Yes

You can append unlimited variables to the URL

http://www.mysite.com?var=a&var2=b&var3=c&var4=etc

HTH
Dan


Thanks, Dan. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum