I am trying to create a login function for a website i am building i am not to fluent in PHP but have been reading a bit to get me started heres what I have so far.
<?php $username = $_POST['username'];
$password = $_POST['password'];
$self = $_SERVER['PHP_SELF'];
$referer = $_SERVER['HTTP_REFERER'];
#if either form field is empty return to the login page
if( ( !$username ) or ( !$password ) )
{ header( "Location:$referer" ); exit(); }
#connect to mysql
$conn = @mysql_connect ("localhost", "mike", "bingo")
or die( "could not connect" );
#select specified database
$rs = @mysql_select_db( "my_database", $conn )
or die( "could not select database" );
#create the sql query
$sql="select * from users where user_name =\"$username\"
and password = password( \"$password\" )";
#execute the 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 login is authenticated
if( $num != 0 )
{ $msg = "Welcome $username - your login succeeded!"; }
else #or return to login page
{ header( "Location:$referer" ); exit(); }
?>
when the login post button is clicked it just posts up ssaying cannot connect, I have put the mySQL database on the remote server and created a simple page to show it can connect to mySQL just to check
if anyone does know a better way than that please post