dark_mirage Posted November 22, 2007 Share Posted November 22, 2007 Hi all, ive recently started learning php and everything is working fine, until today. However, i followed a 'login script' tutorial today and whenever i enter the username and click login, firefox just hangs on the php page which connects to mysql, and in IE it gives a HTTP 500 - Internal server error. I know this is something to do with mysql because when wrote a simple script just to echo a peice of info from the database onto the screen and again, it just hangs, but any other (non mysql related) php script works, any ideas why this happens? :-\ heres the code that checks the login details: <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="pass"; // Mysql password $db_name="mysql"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from signup form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> obviously, i have entered the correct password, just changed it for this lol Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Locked Posted November 22, 2007 Share Posted November 22, 2007 Try adding or die to the query and see if it errors $count=mysql_num_rows($result) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
dark_mirage Posted November 22, 2007 Author Share Posted November 22, 2007 thanks for the quick reply, but it didnt work :/ Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 22, 2007 Share Posted November 22, 2007 What versions are you using? If the case is based on what you stated it is something to do with php/mysql relationship. Check your versions I had similar problem before and it is based on the version incompatability of the two services. Quote Link to comment Share on other sites More sharing options...
dark_mirage Posted November 22, 2007 Author Share Posted November 22, 2007 i have PHP Version 5.2.5 and MYSQL 5.0.41 Quote Link to comment Share on other sites More sharing options...
revraz Posted November 22, 2007 Share Posted November 22, 2007 Replace if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } with if($count==1){ echo "Success"; } To see if the problem is in the header and/or sessions. Quote Link to comment Share on other sites More sharing options...
dark_mirage Posted November 22, 2007 Author Share Posted November 22, 2007 thanks for all your help, but i figured out the problem. I realised that when i installed php, it didnt install the mysql extension by default, so i just added the extension and it works thanks for all your help. Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 22, 2007 Share Posted November 22, 2007 Cool don't forget to click "Topic Solved" 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.