pixeltrace Posted February 18, 2007 Share Posted February 18, 2007 guys, i also need help in my login form, i have 3 page 1. index.php 2. checkuser.php 3. main.php so when i login to index.php - checkuser.php will validate the user once done it will bring me to main.php my problem is, in main.php it not getting the data from checkuser.php let say i have username: peterparker when i get to main.php the field where peterparker's first name and last name should be shown is not appearing but just the variable. this is the code for my index.php <?php include 'db_connect.php'; ?> <form action="checkUser.php" method="post" name="frmLogin"> <table width="260" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#2A4DAB"> <tr> <td width="276"><table width="260" border="0" align="center" cellpadding="4" cellspacing="0"> <tr> <td height="2" colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="2"></td> </tr> <tr> <td colspan="3" bgcolor="#5F9DE3" class="text2">STAFF LOGIN </td> </tr> <tr> <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="2"></td> </tr> <tr> <td width="30%" align="right"><span class="text1">User</span></td> <td colspan="2"align="left"><input name="username" type="username" id="username" /></td> </tr> <tr> <td align="right"><span class="text1">Password</span></td> <td colspan="2" align="left"> <input name="password" type="password" id="password" /> </td> </tr> <tr> <td> </td> <td width="21%"> <input type="submit" name="Submit" value="Login" class="mybutton" /> </td> <td width="49%"> <a href="forgotpass.php" class="link1">forgot your password?</a></td> </tr> <tr> <td> </td> <td colspan="2"> </td> </tr> </table></td> </tr> </table> </form> this is the code for my checkuser.php <? session_start(); $username = $_POST['username']; $password = md5($_POST['password']); if(empty($username) || empty($password)){ echo '<script language=javascript> alert("Please enter ALL of the information!");</script>'; echo '<script language=javascript> top.location = "index.php";</script>'; exit(); } include 'db_connect.php'; $result = mysql_query("SELECT userid, user_level FROM admin_user WHERE username = '{$username}' AND password = '{$password}'"); $numb_rows = mysql_num_rows($result); if($numb_rows == 0) { //NOT A VALID LOGIN/PASSWORD echo '<script language=javascript> alert("You could not be logged in! Either the username and password do not match! Please try again!");</script>'; echo '<script language=javascript> top.location = "index.php";</script>'; die(); } $row = mysql_fetch_assoc($result); $_SESSION['userid'] = $row['userid']; $_SESSION['username'] = $username; $_SESSION['user_level'] = $row['user_level']; mysql_query("UPDATE users SET last_login=now() WHERE userid=" . $row['userid'] . ""); if($row['user_level'] == 'administrator') { header("Location: main.php"); } else if($row['user_level'] == 'staff') { header("Location: main2.php"); } ?> and this is the code for my main.php <? session_start(); if (session_is_registered("username")){ if($_SESSION['user_level'] == 'administrator'){ $username = $_GET['username']; include 'db_connect.php'; $uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; } ?> Welcome <? echo '$first_name $last_name' ?> :: <? echo '$job_title' ?> what's wrong in my codes? need help please! Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/ Share on other sites More sharing options...
desithugg Posted February 18, 2007 Share Posted February 18, 2007 umm im not sure but this might be it in your checkuser.php your using $username = $_POST['username']; $_SESSION['username'] = $username; and in you main.php your using $username = $_GET['username']; I think in you main.php it should be $username = $_SESSION['username']; because your not sending any get variables your just redirecting it to header("main.php"); if it was header("main.php?username=$username"); than i think that will work too Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188072 Share on other sites More sharing options...
pixeltrace Posted February 18, 2007 Author Share Posted February 18, 2007 hi, i changed the codes in main.php already but its still not working this is the current codes in my main.php <? session_start(); if (session_is_registered("username")){ if($_SESSION['user_level'] == 'administrator'){ $username = $_SESSION['username']; include 'db_connect.php'; $uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188083 Share on other sites More sharing options...
desithugg Posted February 18, 2007 Share Posted February 18, 2007 hi, i changed the codes in main.php already but its still not working this is the current codes in my main.php <? session_start(); if (session_is_registered("username")){ if($_SESSION['user_level'] == 'administrator'){ $username = $_SESSION['username']; include 'db_connect.php'; $uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; } ?> your missing one or two } at the end it should be <? session_start(); if (session_is_registered("username")){ if($_SESSION['user_level'] == 'administrator'){ $username = $_SESSION['username']; include 'db_connect.php'; $uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; } } } ?> if that doesnt work try taking one off thats the only problem i see Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188093 Share on other sites More sharing options...
pixeltrace Posted February 18, 2007 Author Share Posted February 18, 2007 its still not working. this is the error i am getting Parse error: parse error, unexpected '}' in c:\hosting\webhost4life\member\diorgrace\admean\main.php on line 77 this is the current entire codes in my main.php page <? session_start(); if (session_is_registered("username")){ if($_SESSION['user_level'] == 'administrator'){ $username = $_SESSION['username']; include 'db_connect.php'; $uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; } } } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>:: JobHiRings :: Administration Page</title> <style type="text/css"> <!-- body { margin-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; } --> </style> <link href="../CSS.css" rel="stylesheet" type="text/css"> <link href="css.css" rel="stylesheet" type="text/css"> </head> <body> <table width="778" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="3"><img src="images/header.gif" width="778" height="148"></td> </tr> <tr> <td width="16" rowspan="2" align="left" valign="top" background="images/left.gif"><img src="images/left.gif" width="16" height="14"></td> <td width="745" valign="top"><table width="746" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="746" colspan="2"> </td> </tr> <tr> <td colspan="2">Welcome <? echo '$first_name $last_name' ?> :: <? echo '$job_title' ?></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2"> </td> </tr> </table></td> <td width="16" rowspan="2" align="right" valign="top" background="images/right.gif"><img src="images/spacer.gif" width="1" height="1"><img src="images/right.gif" width="16" height="14"></td> </tr> <tr> <td valign="top"><img src="images/spacer.gif" width="746" height="10"></td> </tr> <tr> <td colspan="3" background="images/footer.gif"><table width="583" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="12" rowspan="2"><img src="images/spacer.gif" width="12" height="43"></td> <td width="560" height="10" valign="top"><img src="images/spacer.gif" width="12" height="10"></td> <td width="12" rowspan="2"><img src="images/spacer.gif" width="12" height="43"></td> </tr> <tr> <td align="center" valign="top" class="footer">Copyright © 2007 www.jobhirings.com. All Rights Reserved</td> </tr> </table></td> </tr> </table> <? }else{ echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='index.php'>Login</a></font>"; } }else{ echo '<script language=javascript>top.location = "index.php";</script>'; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188097 Share on other sites More sharing options...
desithugg Posted February 18, 2007 Share Posted February 18, 2007 umm nvm than i taught you were missing the }} because you didn't post the total code but im not sure what the problem is what exactly is happening blank page? Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188105 Share on other sites More sharing options...
pixeltrace Posted February 18, 2007 Author Share Posted February 18, 2007 in the main page instead of welcome peter parker :: spiderman this is appearing welcome $first_name $last_name :: $job_title what could be wrong in my codes? is it in the main.php or in the checkuser.php? need help thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188115 Share on other sites More sharing options...
desithugg Posted February 18, 2007 Share Posted February 18, 2007 <? session_start(); if (session_is_registered("username")){ if($_SESSION['user_level'] == 'administrator'){ $username = $_SESSION['username']; include 'db_connect.php'; $uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>:: JobHiRings :: Administration Page</title> <style type="text/css"> <!-- body { margin-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; } --> </style> <link href="../CSS.css" rel="stylesheet" type="text/css"> <link href="css.css" rel="stylesheet" type="text/css"> </head> <body> <table width="778" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="3"><img src="images/header.gif" width="778" height="148"></td> </tr> <tr> <td width="16" rowspan="2" align="left" valign="top" background="images/left.gif"><img src="images/left.gif" width="16" height="14"></td> <td width="745" valign="top"><table width="746" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="746" colspan="2"> </td> </tr> <tr> <td colspan="2">Welcome<? echo " ".$first_name." ".$last_name." "; ?>:: <? echo $job_title; ?></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2"> </td> </tr> </table></td> <td width="16" rowspan="2" align="right" valign="top" background="images/right.gif"><img src="images/spacer.gif" width="1" height="1"><img src="images/right.gif" width="16" height="14"></td> </tr> <tr> <td valign="top"><img src="images/spacer.gif" width="746" height="10"></td> </tr> <tr> <td colspan="3" background="images/footer.gif"><table width="583" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="12" rowspan="2"><img src="images/spacer.gif" width="12" height="43"></td> <td width="560" height="10" valign="top"><img src="images/spacer.gif" width="12" height="10"></td> <td width="12" rowspan="2"><img src="images/spacer.gif" width="12" height="43"></td> </tr> <tr> <td align="center" valign="top" class="footer">Copyright © 2007 www.jobhirings.com. All Rights Reserved</td> </tr> </table></td> </tr> </table> <? }else{ echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='index.php'>Login</a></font>"; } }else{ echo '<script language=javascript>top.location = "index.php";</script>'; } ?> </body> </html> the problems definitly in main.php and there i fixed it i think you were missing ; at the end of echo'' but try copying th code above Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188117 Share on other sites More sharing options...
pixeltrace Posted February 18, 2007 Author Share Posted February 18, 2007 hi, i tried this but its not showing the values. only welcome :: instead of welcome peter parker :: spiderman thanks! Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188122 Share on other sites More sharing options...
desithugg Posted February 18, 2007 Share Posted February 18, 2007 thats weird try checking if the values are even gotten from the database try and echo them right after the query to make sure the login check is working if thats working try changing <td colspan="2">Welcome<? echo " ".$first_name." ".$last_name." "; ?>:: <? echo $job_title; ?></td> to <td colspan="2">Welcome<? echo " $first_name $last_name "; ?>:: <? echo $job_title; ?></td> Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188128 Share on other sites More sharing options...
pixeltrace Posted February 18, 2007 Author Share Posted February 18, 2007 Hi, Its still the same. welcome :: instead of welcome peter parker :: spiderman i checked the database and there a value for first_name, last_name and job_title there Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188130 Share on other sites More sharing options...
desithugg Posted February 18, 2007 Share Posted February 18, 2007 include 'db_connect.php'; $uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'"; $uResult = mysql_query($uSql, $connection); there not showing up because your not assigning the variables try $query = mysql_query("SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'") or die(mysql_error()); $row = mysql_fetch_array( $query ); $first_name = $row["first_name"]; $last_name = $row["last_name"]; $job_title = $row["job_title"]; Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188135 Share on other sites More sharing options...
pixeltrace Posted February 18, 2007 Author Share Posted February 18, 2007 thanks man! its working now! just one last question. what is the "." for? the one that you placed before and after first_name and last_name <? echo " ".$first_name." ".$last_name." "; ?> :: <? echo "$job_title"; ?> thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188143 Share on other sites More sharing options...
desithugg Posted February 18, 2007 Share Posted February 18, 2007 hey np, it's so you can place more than one variable for example if you wanna echo $firstname $s = "$firstnames"; will just echo s but $s = "".$firstname."s"; will echo firstname's hard to explain lol Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188145 Share on other sites More sharing options...
bobleny Posted February 18, 2007 Share Posted February 18, 2007 If this helps any, basically the period is a separator. Everything in the quotes of an echo, will be echoed. if you echo: echo "$grge rules"; then your browser will spell out: $grge rules but, if you echo: echo $grge . "rules"; then your browser will spell out: George rules or if you echo: echo "I think" . $grge . "smells"; then your browser will spell out: I think George smells The dot acts as a separator between variables and exact phrases... If you want to see, try this: <?php $grge = George; echo "$grge rules"; echo "<br />; echo $grge . "rules"; echo "<br />; echo "Rules does," . $grge; echo "<br />; echo "I think" . $grge . "smells"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188155 Share on other sites More sharing options...
pixeltrace Posted February 19, 2007 Author Share Posted February 19, 2007 thanks for the explanation. it helped. Quote Link to comment https://forums.phpfreaks.com/topic/39046-need-help-in-my-login-form/#findComment-188399 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.