Hi, i need some help with this code im using to collect names from my mysql database and use that as login for users. So far when the submit button is clicked it displays nothing more than a blank page with the url of the checklogin script. Suggesting that it cannot find a match in my database… ive checked this and they are definatley in my data base? please help…
<?php
if(isset($_POST['submit'])){ //check for submit button click
$username = $_POST['myusername'];
$password = $_POST['mypassword']; // proceed with rest of code
$self = $_SERVER['PHP_SELF'];
$referer = $_SERVER['HTTP_REFERER'];
#if either form field is empty return to the log-in page
if( (!$username ) or (!$password ) )
{ header( "Location:$referer" ); exit(); }
#connect to mysql
$conn = @mysql_connect( "server", "username", "password" )
or die( "Could not connect" );
#select database
$rs = @mysql_select_db( "removalspacelogin", $conn )
or die ( "Could not select db" );
#create query
$sql="select * from users where username = '$username' and password = '$password')";
#execute query
$rs = mysql_query( $sql, $conn )
or die( "Could not execute query" );
#get number of rows that match username and password
$num = mysql_numrows( $rs );
#if there is a match the log-in is done
if( $num != 0 )
{ $msg = "Welcome $username - your log-in was successful!"; }
else #or return to: login.php
{ header( "Location:$referer" ); exit(); }
}
?>
<html> <head><title>Check-login</title></head>
<body> <?php echo( $msg ); ?> </body> </html>
Html form with the submit button that executes the script (or should so)…
<form name="form1" method="post" action="check_login2.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><span class="style7"><strong>Member Login </strong></span></td>
</tr>
<tr>
<td width="78"><span class="style7">Username</span></td>
<td width="6"><span class="style7">:</span></td>
<td width="294"><input name="myusername" type="text" class="style7" id="myusername"></td>
</tr>
<tr>
<td><span class="style7">Password</span></td>
<td><span class="style7">:</span></td>
<td><input name="mypassword" type="password" class="style7" id="mypassword"></td>
</tr>
<tr>
<td><span class="style7"></span></td>
<td><span class="style7"></span></td>
<td><input name="Submit" type="submit" class="style7" value="Login" /></td>
</tr>
</table>
</td>
</form>
Can any of you find the problem here? many thanks