pure_skill_2000 Posted December 23, 2007 Share Posted December 23, 2007 Hi My login form wont work for some reason, any ideas? <form name="authenticate" method="post" action="wk9ex2.php"> <input name="login id" type="text" value="loginid" size="20"/><br > <input name="password" type="text" value="password" size="20"/><br> <input type="submit" name="submit" value="submit"/> <input type="reset" name="reset" value="reset"/> <?php //Database Information $dbhost = ""; $dbname = ""; $dbuser = ""; $dbpass = ""; //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql="SELECT loginid FROM week9 WHERE loginid='".$loginid.”’ and password=’”.$password.”’”; $r = mysql_query($sql); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_affected_rows()==0){ print "no such login in the system. please try again."; exit(); } else{ echo loggedin.php //proceed to perform website’s functionality – e.g. present information to the user } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/ Share on other sites More sharing options...
shocker-z Posted December 23, 2007 Share Posted December 23, 2007 HOPE THATS NOT YOUR ACTUAL USER AND PASS!!!!? you haven't defined $loginid and $password try this <form name="authenticate" method="post" action="wk9ex2.php"> <input name="login id" type="text" value="loginid" size="20"/><br > <input name="password" type="text" value="password" size="20"/><br> <input type="submit" name="submit" value="submit"/> <input type="reset" name="reset" value="reset"/> <?php //Database Information $dbhost = ""; $dbname = ""; $dbuser = ""; $dbpass = ""; //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $loginid=mysql_real_escape_string($_POST['login id']); $password=mysql_real_escape_string($_POST['password']); $sql="SELECT loginid FROM week9 WHERE loginid='".$loginid.”’ and password=’”.$password.”’”; $r = mysql_query($sql); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_affected_rows()==0){ print "no such login in the system. please try again."; exit(); } else{ echo loggedin.php //proceed to perform website’s functionality – e.g. present information to the user } ?> Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-421928 Share on other sites More sharing options...
pure_skill_2000 Posted December 23, 2007 Author Share Posted December 23, 2007 This produces an syntax error, unexpected '=' Error on line 33 Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-421931 Share on other sites More sharing options...
shocker-z Posted December 23, 2007 Share Posted December 23, 2007 What is line 33 in your code as i make it out to be exit(); but do you have more code at the top or somthing as i cant see an issue with the code i inserted. Liam Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-421935 Share on other sites More sharing options...
pure_skill_2000 Posted December 23, 2007 Author Share Posted December 23, 2007 $sql="SELECT loginid FROM week9 WHERE loginid='".$loginid.”’ and password=’”.$password.”’”; Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-421936 Share on other sites More sharing options...
corbin Posted December 23, 2007 Share Posted December 23, 2007 Try $sql="SELECT loginid FROM week9 WHERE loginid='{$loginid}' and password='{$password}'"; Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-421937 Share on other sites More sharing options...
shocker-z Posted December 23, 2007 Share Posted December 23, 2007 use this $sql="SELECT loginid FROM week9 WHERE loginid='".$loginid."' and password='".$password."'"; You used the wrong " and ' simbols.. Could possibly have been just when you pasted or editor you used.. Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-421938 Share on other sites More sharing options...
pure_skill_2000 Posted December 23, 2007 Author Share Posted December 23, 2007 Below is my code atm, it still inst working though, when I click to send the information it just refreshes the page instead of going to the logged in page Any ideas? <form name="authenticate" method="post" action="wk9ex2.php"> <input name="login id" type="text" value="loginid" size="20"/><br > <input name="password" type="text" value="password" size="20"/><br> <input type="submit" name="submit" value="submit"/> <input type="reset" name="reset" value="reset"/> <?php //Database Information //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $loginid=mysql_real_escape_string($_POST['login id']); $password=mysql_real_escape_string($_POST['password']); $sql="SELECT username FROM week9 WHERE username='".$loginid."' and password='".$password."'"; $r = mysql_query($sql); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_affected_rows()==0){ print "no such login in the system. please try again."; exit(); } else{ echo loggedin.php; //proceed to perform website’s functionality – e.g. present information to the user } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-421943 Share on other sites More sharing options...
chris_rulez001 Posted December 23, 2007 Share Posted December 23, 2007 Below is my code atm, it still inst working though, when I click to send the information it just refreshes the page instead of going to the logged in page Any ideas? <form name="authenticate" method="post" action="wk9ex2.php"> <input name="login id" type="text" value="loginid" size="20"/><br > <input name="password" type="text" value="password" size="20"/><br> <input type="submit" name="submit" value="submit"/> <input type="reset" name="reset" value="reset"/> <?php //Database Information //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $loginid=mysql_real_escape_string($_POST['login id']); $password=mysql_real_escape_string($_POST['password']); $sql="SELECT username FROM week9 WHERE username='".$loginid."' and password='".$password."'"; $r = mysql_query($sql); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_affected_rows()==0){ print "no such login in the system. please try again."; exit(); } else{ echo loggedin.php; //proceed to perform website’s functionality – e.g. present information to the user } ?> this section of your code might be causing a problem: echo loggedin.php; try: include("loggedin.php"); does your code work after you made the alteration? to the bit i pointed out Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-421959 Share on other sites More sharing options...
pure_skill_2000 Posted December 24, 2007 Author Share Posted December 24, 2007 Hi I made that change but it didnt seem to make any difference The form just reposts a blank empty form, it does not seem to check the login and proceed to the logged in page Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-422070 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Share Posted December 24, 2007 Check all your code from all scripts, not getting MySQL error? Yes, try <?php include("loggedin.php"); use the <?php statement instead of <? tell me if you get any result Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-422096 Share on other sites More sharing options...
shocker-z Posted December 24, 2007 Share Posted December 24, 2007 use this <?php //Database Information //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $loginid=mysql_real_escape_string($_POST['login id']); $password=mysql_real_escape_string($_POST['password']); $sql="SELECT username FROM week9 WHERE username='".$loginid."' and password='".$password."'"; $r = mysql_query($sql); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_num_rows($r)==0){ print "no such login in the system. please try again."; ?> <form name="authenticate" method="post" action="wk9ex2.php"> <input name="login id" type="text" value="loginid" size="20"/><br > <input name="password" type="text" value="password" size="20"/><br> <input type="submit" name="submit" value="submit"/> <input type="reset" name="reset" value="reset"/> <?php } else { include('loggedin.php'); //proceed to perform website’s functionality – e.g. present information to the user } ?> I have made it so your form will show when not validated and when validated you will include the loggedin.php file. I changed mysql_affected_rows() to mysql_num_rows($row) as mysql_affected_rows is only used after updating a table, this will always be 0 when selecting from a table. Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/82957-solved-login-not-working/#findComment-422309 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.