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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking to another page

Status
Not open for further replies.

kjspear

Programmer
Feb 13, 2002
173
US
I have set up a login page in php. I'm using the if statements for the query results. Basically what I'm trying to do is if the user ID is found then automatically go to another page. What is the proper syntax in PHP. I want to link to a page like <a href=&quot;myhome.php&quot;</a>. Here part of the code;

mysql_select_db(&quot;mylogin&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)
{
print &quot;<h2>Invalid Username or Password.</h2>&quot;;
}else{
THIS IS WHERE I NEED THE LINK TO BE AT. IF THE USER NAME IS FOUND THEN THE LINK HERE WILL AUTOMATICALLY SED THE USER TO ANOTHER PAGE.
}



?>
Thank You
Kyle
 
if (mysql_num_rows($result)==0)
{
print &quot;<h2>Invalid Username or Password.</h2>&quot;;
}else
{
header(&quot;Location:pHP_PAGE_HERE&quot;);
exit();
/Location or location (not sure bout the L caps...
}


Known is handfull, Unknown is worldfull
 
O.K., here's was I did;


mysql_select_db(&quot;mylogin&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)
{
print &quot;<h2>Invalid Username or Password.</h2>&quot;;
}else{
header(&quot;location:page1.php&quot;);

}
?>


But know I get the following error;

Warning: Cannot modify header information - headers already sent by
(output started at C:\mysql\data\mylogin\myuserslu.php:4) in
C:\mysql\data\mylogin\myuserslu.php on line 12


I'm not sure what this means. This is how I have it set up, I used a form in html for the user to fill out.The php script above takes those varibles and processes the entry. If the user's information is found, then the user is automatically taken to another page. If the user information is not found, then the Invalid user/password message is displayed. I'm using php4.

Any suggestions?
Thanks
Kyle
 
simple,
before the header line there must be no print/echo statements. that is nothing must be otputted to the browser...

Known is handfull, Unknown is worldfull
 
It worked. Now since there must be no print/echo statements prior to the 'header(&quot;location:page1.php&quot;);' statement, I will rearrange my code.

Thanks for your help.

Kyle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top