Jump to content

[SOLVED] HTTP 500 - Internal server error


dark_mirage

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/78450-solved-http-500-internal-server-error/
Share on other sites

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.

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.

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 :D thanks for all your help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.