Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem will passing variables to another page 1

Status
Not open for further replies.

kjspear

Programmer
Joined
Feb 13, 2002
Messages
173
Location
US
Hello,

I seen to be having a minor problem will passing variables to another page. Here's what I have so far.

<?php
$conn=mysql_connect(&quot;localhost&quot;,&quot;user&quot;,&quot;password&quot;)
or die(&quot;Could not connect &quot; . mysql_error());
//print &quot;Connected successfully&quot;;
mysql_select_db(&quot;mylog&quot;,$conn) or die(&quot;Could not select database&quot;);
$sql = &quot;select userid from logins where userID='$userID' and passID = '$passID'&quot;;
$result=mysql_query($sql);
if (mysql_num_rows($result)!=0)
{

header('location:peter.php?$userID');


}else{

print &quot;<h2>Invalid Username or Password.</h2>&quot;;

}




?>

---------------------------Code for the next page-------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
My Next Page
<?php
print $userID;
?>
</body>
</html>

However, I get a Notice: Undefined variable: userID in C:\mysql\data\mylogin\peter.php on line 10

The varible will not pass to the next page.

Any assistance would be helpful.

Thanks
KJ
 
It's probably this line:

header('location:peter.php?$userID');


You've passed the script a value, but have given it no variable name to associate with that value. Also, you're using single-quoted strings. Inside single quotes, PHP does not interpolate variables, so the line above is setting a header which reads:

location:peter.php?$userID


Try

header('location:peter.php?userID='.$userID);


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Yes, that was the problem! It works now.

I used the suggested code;

header('location:peter.php?userID='.$userID);

Thanks a million.
KJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top