PHP script won't do as wished

June 23, 2011 at 07:07:07
Specs: Windows Vista
I want the PHP script to Login on the index.php and show details from the logged in account all read from separate tables.

So far all it does is redirect to a page connect.php (to check the username / password combination) if wrong it tells the user the username and/or password is incorrect, if correct it redirects to login_succes.php and shows "Login successful!"

If someone could look into the scripts and tell me what's wrong (and / or provide a fixed version) it would be highly appreciated.

index.php Login form:
<h1>Member Login</h1>

<form method="post" name="Loginform" action="connect.php" autocomplete="off" >

Username:<br />
<input type="text" name="Username" id="Username"/>

Password:<br />
<input type="password" name="Password" id="txtPassword"/>
<br />
<table cellpadding="3">
<td align="center"><input type="submit" value="Login to AnimeNationRO" name="Submit" /></td>


$host="localhost"; // Host name
$username="root"; // Mysql username
$password="Gemeente3!"; // Mysql password
$db_name="ragnarok"; // Database name
$tbl_name="login"; // 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 form

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE userid='$myusername' and user_pass='$mypassword'";

// Mysql_num_row is counting table row
// If result matched $myusername and $mypassword, table row must be 1 row

// Register $myusername, $mypassword and redirect to file "login_success.php"
else {
echo "Wrong Username or Password";


Login Successful

See More: PHP script wont do as wished

Report •

July 5, 2011 at 19:40:30
In your form change the action to action="index.php" and put your login script in index.php page probably above the form and put a condition if the form is submitted, you can do like this:

if (isset($_POST) {
//put your login code here.

Report •
Related Solutions

Ask Question