Click to See Complete Forum and Search --> : Problems passing variables to URL
rpleasan
05-12-2007, 10:17 AM
Sorry about the additional title posts...but....
I'm creating a seller login that will pass the sellerid to a account summary page. The login part works fine and pulls the username/password from the database to authenticate. But, the sellerid isn't being displayed on the account summary page. Any ideas?
login:
// check if the user id and password combination exist in database
$sql = "SELECT Sellerid FROM sellerinfo WHERE Username = '$userId' AND Password = '$password'";
// after login we move to the main page
header('Location: accountsummary.php?Sellerid');
account summary:
<?php
$sellerid = $_GET['Sellerid'];
echo "The seller ID is $sellerid";
?>
kurniawan
05-12-2007, 10:46 AM
You have to put value behind the variable name :
// after login we move to the main page
header('Location: accountsummary.php?Sellerid=' . $Sellerid);
--------------------------------
http://anaknegri.com http://pajaknenkin.com http://arifkurniawan.net
http://ppi-kansai.net http://kti2007.ppi-kansai.net
Taschen
05-12-2007, 10:51 AM
header('Location: accountsummary.php?Sellerid');
account summary:
<?php
$sellerid = $_GET['Sellerid'];
echo "The seller ID is $sellerid";
?>
$sellerid in you code refers to an array key - as in:
accountsummary.php?key(=val)
If you want $sellerid to be a value you need to add a value to accountsummary.php?Sellerid like so:
header('Location: accountsummary.php?Sellerid=123');
Now $sellerid will return 123.
<?php
$sellerid = $_GET['Sellerid'];
echo "The seller ID is $sellerid"; //will return 123
?>
Using an array key as a dynamic value isn't really a good idea, but have alook at the php manual for array keys to learn more:
http://www.php.net/manual/en/function.array-keys.php
rpleasan
05-12-2007, 10:58 AM
Cool. This is what I see when the account summary page comes up;
The seller ID is
The url reads: http://www.tttt.com/seller_status.php?Sellerid=
Is the does the Sellerid from the database contain any data?
kurniawan
05-12-2007, 11:05 AM
This will give what you want :
// check if the user id and password combination exist in database
$sql = "SELECT Sellerid FROM sellerinfo WHERE Username = '$userId' AND Password = '$password'";
list($Sellerid)=mysql_fetch_row($sql);
// after login we move to the main page
header('Location: accountsummary.php?Sellerid=' . $Sellerid);
----------------------------------------
http://anaknegri.com http://pajaknenkin.com http://arifkurniawan.net
http://ppi-kansai.net http://kti2007.ppi-kansai.net
Taschen
05-12-2007, 11:06 AM
If you query your database using
(http://www.tttt.com/seller_status.php?Sellerid=)
$sellerid = $_GET[Sellerid]
WHERE sellerid = $sellerid
you won't get anything because the value of $_GET[Sellerid] is nothing. I.e. there is no value after the "Sellerid=" in your example above.
On the other hand "Sellerid=123" will return a value to $sellerid which can be used in a db query.
Taschen
05-12-2007, 11:07 AM
kurniawan you have faster fingers than me you keep getting your post in just as I'm submitting mine.
kurniawan
05-12-2007, 11:10 AM
:) :D
---------------------------------------------
http://anaknegri.com http://pajaknenkin.com http://arifkurniawan.net
http://ppi-kansai.net http://kti2007.ppi-kansai.net
rpleasan
05-12-2007, 11:44 AM
Kurn,
When I added your code; list($Sellerid)=mysql_fetch_row($sql);
I got this error;Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/s/h/e/login3.php on line 15
rpleasan
05-12-2007, 11:48 AM
If you query your database using
(http://www.tttt.com/seller_status.php?Sellerid=)
$sellerid = $_GET[Sellerid]
WHERE sellerid = $sellerid
you won't get anything because the value of $_GET[Sellerid] is nothing. I.e. there is no value after the "Sellerid=" in your example above.
On the other hand "Sellerid=123" will return a value to $sellerid which can be used in a db query.
Tas,
I was assuming that sending the Sellerid variable in my url, I could get the $_GET[] function to capture it and then reassign it. Is there a way to do this?
rpleasan
05-12-2007, 12:02 PM
If you query your database using
(http://www.tttt.com/seller_status.php?Sellerid=)
$sellerid = $_GET[Sellerid]
WHERE sellerid = $sellerid
you won't get anything because the value of $_GET[Sellerid] is nothing. I.e. there is no value after the "Sellerid=" in your example above.
On the other hand "Sellerid=123" will return a value to $sellerid which can be used in a db query.
Tas,
Wouldnt Seller=' . $Sellerid have the Sellerid value from my select statement?
// check if the user id and password combination exist in database
$sql = "SELECT Sellerid FROM sellerinfo WHERE Username = '$userId' AND Password = '$password'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
// after login we move to the main page
header('Location: seller_status.php?Sellerid=' . $Sellerid);
Taschen
05-12-2007, 12:12 PM
No but it could have the variable $userId. However, the sellerid and username are two seperate fields in your table.
Sellerid in your select statement refers to a field in the table sellerinfo etc.
You could use:
$query = 'SELECT Sellerid WHERE etc';
$result = mysql_query($query);
$result = mysql_fetch_array($result);
return $result['Sellerid'];
header('Location: seller_status.php?Sellerid=' . $result['Sellerid']);
Taschen
05-12-2007, 12:25 PM
Tas,
I was assuming that sending the Sellerid variable in my url, I could get the $_GET[] function to capture it and then reassign it. Is there a way to do this?
$_GET is a super variable, I'm not sure if perhaps you are mixing up / misunderstanding array-value pairings.
Try the following:
$hello = 'hello';
print_r($hello); //This will return "hello" plain and simple
Now try:
$hello['welcome'] = 'hello';
print_r($hello); //This will return "Array ( [welcome] => hello )"
if you use print_r($_GET) on the URL you are trying to use you will see the key-value pair "page.php?Sellerid=" returns "Array ([Sellerid] => )"
Can you extract the key [Sellerid] from the $_GET var array? Well yes (see response further up page). But keys are not meant as means of conveying dynamic data (though keys are/can be dynamic).
kurniawan
05-12-2007, 09:28 PM
Kurn,
When I added your code; list($Sellerid)=mysql_fetch_row($sql);
I got this error;Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/s/h/e/login3.php on line 15
I am really very sorry, I missed one command. You should add mysql_query() :
// check if the user id and password combination exist in database
$sql = mysql_query("SELECT Sellerid FROM sellerinfo WHERE Username = '$userId' AND Password = '$password'");
list($Sellerid)=mysql_fetch_row($sql);
// after login we move to the main page
header('Location: accountsummary.php?Sellerid=' . $Sellerid);
If you notice my method is similar to Taschen's, the different is I use fetch_row and list() to extract the array value so you can make the result with smaller script.
I am not expert, but I learnt that assign the value of query into variable will save time and resources. So, whether you use fetch_row or fetch_array, you'd better assign the value into variable so you only have to call $Sellerid instead of $result['Sellerid'] everytime you need it.
-------------------------------------------------------
http://anaknegri.com http://pajaknenkin.com http://arifkurniawan.net
http://ppi-kansai.net http://kti2007.ppi-kansai.net