JamesThePanda Posted November 14, 2009 Share Posted November 14, 2009 Hi I have been watching this video on you tube about making your own php login form. I can' seem to get it to work for me here is the coe for the form im using at the moment <html> <BODY> </BODY> <form method="post" action= "logincheck.php" name="form1"> <label for="username">Username:</label> <input type="text" name="myusername" id="myusername" /> <label for="password">Password:</label> <input type="text" name="mypassword" id="mypassword" /> <input type="submit" name="submit" value="login"/> </form> </html> and here is the code for the scipt <?php $host = "localhost"; $username = "root"; $password = ""; $db_name = "members"; $tbl_name = "memtable"; mysql_connect( '$host', '$username', '$password') or die (mysql_error()); mysql_select_db($db_name) or die (mysql_error()); $myusername = $_POST['myusername']; $mypassword = $_POST['mypassword']; $sql = "SELECT * FROM $tbl_name WHERE username = '$myusername' and password = '$mypassword'; $result = mysql_query($sql); $count = mysql_num_rows($result); if ($count==1){ session_register("myusername"); session_register("muypassword"); header("location:login_success.php"); } else { echo "wrong username or password"; } ?> I cant seem to understand what the problem is. It is saying there is a problem on line20 Thanks James Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted November 14, 2009 Share Posted November 14, 2009 try this instead: <?php $host = "localhost"; $username = "root"; $password = ""; $db_name = "members"; $tbl_name = "memtable"; mysql_connect($host,$username,$password) or die (mysql_error()); mysql_select_db($db_name) or die (mysql_error()); $myusername = $_POST['myusername']; $mypassword = $_POST['mypassword']; $sql = "SELECT * FROM $tbl_name WHERE username = '$myusername' and password = '$mypassword'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if ($count==1){ session_register("myusername"); session_register("muypassword"); header("location:login_success.php"); } else { echo "wrong username or password"; } ?> You were missing a closing " on your query. Also I removed the ' around the $host,$username,and $password in the mysql_connect as it is not needed. Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted November 14, 2009 Author Share Posted November 14, 2009 ok did that Im still get a error It says is a parse error online 20 ? any hints? Thanks James Quote Link to comment Share on other sites More sharing options...
almightyegg Posted November 14, 2009 Share Posted November 14, 2009 I think it's because you need to start the file with session_start() to enable the use of sessions Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted November 14, 2009 Author Share Posted November 14, 2009 @almightyegg what code do I put in and were? Thanks James Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted November 14, 2009 Share Posted November 14, 2009 yes you also need to start the session. however it is not needed at the top of the page in this case since it is the login. you can start the session when you know the information is correct. so try this: <?php $host = "localhost"; $username = "root"; $password = ""; $db_name = "members"; $tbl_name = "memtable"; mysql_connect($host,$username,$password) or die (mysql_error()); mysql_select_db($db_name) or die (mysql_error()); $myusername = $_POST['myusername']; $mypassword = $_POST['mypassword']; $sql = "SELECT * FROM $tbl_name WHERE username = '$myusername' and password = '$mypassword'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if ($count==1){ session_start(); session_register("myusername"); session_register("muypassword"); header("location:login_success.php"); } else { echo "wrong username or password"; } ?> Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted November 14, 2009 Author Share Posted November 14, 2009 hmmm that still didnt seem to do anything here is the exact error I get Parse error: parse error in C:\wamp\www\membership\logincheck.php on line 20 thanks James Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted November 14, 2009 Share Posted November 14, 2009 replace this line: if ($count==1){ with this: if($count==1){ all I did was remove the space between the if and the (. i dont know if it doesnt like spaces or not but i dont use them between there. Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted November 14, 2009 Author Share Posted November 14, 2009 done that still nothing I wass wondering could it be something with the sql\? Thanks James Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted November 14, 2009 Author Share Posted November 14, 2009 ok made a little break through Im getting errors on lines 11 and 12 saying that myusername and mypassword are undefined functions the previous error was because wasnt saving the file properly sry new comp Thanks James Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted November 14, 2009 Share Posted November 14, 2009 That doesnt make any sense looking at the code that I provided above. The only thing that I can think of is that you forgot the $ in front of the variable name. I would make sure you copied the code correctly and that it is registered on the server correctly. Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted November 15, 2009 Author Share Posted November 15, 2009 I got it to work thanks everyone for ya help Quote Link to comment 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.