freddyw Posted July 17, 2009 Share Posted July 17, 2009 I have a registration from that works. The user enters the information and it is stored in the database. This is the code for that <html> <head><title> Register </title></head> <body> <?php if(isset($_POST['first_name'])){ $first_name = pg_escape_string($_POST['first_name']); $last_name = pg_escape_string($_POST['last_name']); $username = pg_escape_string($_POST['username']); $password = pg_escape_string($_POST['password']); if ( ( !$first_name ) or (!$last_name) or (!$username) or (!$password) ){ die("Missing some values"); } $conn = @pg_connect("=======connection details hidden==========="); $psql = "INSERT INTO users(first_name,last_name,username,password) VALUES ('$first_name','$last_name','$username','$password ')"; $result = pg_query($psql) or die ("Could not execute query"); if ( $result ) { echo "Congratulations, You can now log into Sporticket with the username and password you supplied"; } else { echo "Failed to add user"; } }else{ $form ="Please enter your details below to register with Sporticket"; $form.="<form action=\"\""; $form.=" method=\"post\"> First Name: "; $form.="<input type=\"text\" name=\"first_name\""; $form.=" <br>Last Name: "; $form.="<input type=\"text\" name=\"last_name\""; $form.=" <br>Username: "; $form.=" <input type=\"text\" name=\"username\""; $form.=" <br>Password: "; $form.=" <input type=\"password\" name=\"password\""; $form.=" <br>"; $form.=" <input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo $form; } ?> </body> </html> I don't need help with that. Then there is the log in page (html) <html> <head><title>Log In</title></head> <body>Please Enter Your Login Details</body> <form action = "login.php" method = "post"> Username:<br> <input type = "text" name = "username"> <br><br> Password:<br> <input type = "password" name = "password"> <br><br> <input type = "submit" value = "Log in"> </form> </body> </html> Thats all fine. Im creating the login.php and I'm stuck. I know what im trying to do, and I've entered comments in so you can see what I'm aiming for. I just dont know how to code it. Any help would be massively appreciated. this is what i have so far. I dont know if this will work. I've also added a comment saying i dont know the code here. Thats where I'm very stuck. <?php $username = pg_escape_string($_POST['username']); $password = pg_escape_string($_POST['password']); $referer = $_SERVER ['HTTP_REFERER'] ; #this will make user return to login page if a field is left empty if ( ( !$username ) or (!$password) ) { header ( "location:$referer" ); exit(); } $conn = @pg_connect("=======connection details hidden==========="); $psql="select * from users where username =\"$username\" and password = password (\"$password\")"; $rs = @pg_connect ($psql, $conn) or die ("could not execute query"); #get number of rows that match username and password $num = #i dont know the code to go here #if there is a match log in successful if ( $num !=0 ) { $msg = "Welcome $username - You are logged in"; } else #return to log in page { header ( "location:$referer" ); exit(); } ?> <html> <head><title>You are logged in</title></head> <body> <?php echo ( $msg ); ?> </body> <html> If you have the time id appreciate your help. Im using PHP 5 and im not using MySql. Link to comment https://forums.phpfreaks.com/topic/166349-cant-finish-log-in-page/ Share on other sites More sharing options...
Stuie_b Posted July 17, 2009 Share Posted July 17, 2009 To get the number of rows that a certain query returns you can simply use pg_num_rows() or mysql_num_rows() depending on your database, See here for pg_num_rows() See here for mysql_num_rows() The function is very straight forward, simply provide it with the database query handle and it will return the number of rows. Stuie Link to comment https://forums.phpfreaks.com/topic/166349-cant-finish-log-in-page/#findComment-877187 Share on other sites More sharing options...
freddyw Posted July 17, 2009 Author Share Posted July 17, 2009 thanks for that stuie_b i think i've finished the page. but im getting this error msg Parse error: syntax error, unexpected T_IF in /home2/webusers/07/344740/public_html/sporticket/login.php on line 24 this is no my login.php <? $username = pg_escape_string($_POST['username']); $password = pg_escape_string($_POST['password']); $referer = $_SERVER ['HTTP_REFERER'] ; #this will make user return to login page if a field is left empty if ( ( !$username ) or (!$password) ) { header ( "location:$referer" ); exit(); } $conn = @pg_connect("connection details"); $psql="select * from users where username =\"$username\" and password = password (\"$password\")"; $rs = @pg_connect ($psql, $conn) or die ("could not execute query"); #get number of rows that match username and password $num = pg_num_rows($rs) #if there is a match log in successful if ( $num !=0 ) { $msg = "Welcome $username - You are logged in"; } else #return to log in page { header ( "location:$referer" ); exit(); } ?> <html> <head><title>You are logged in</title></head> <body> <? echo ( $msg ); ?> </body> <html> [code] Link to comment https://forums.phpfreaks.com/topic/166349-cant-finish-log-in-page/#findComment-877219 Share on other sites More sharing options...
freddyw Posted July 17, 2009 Author Share Posted July 17, 2009 i realised i didnt have the ; on line 24. ive fixed that now and its saying could not execute query, can anyone see why? Link to comment https://forums.phpfreaks.com/topic/166349-cant-finish-log-in-page/#findComment-877262 Share on other sites More sharing options...
ldougherty Posted July 17, 2009 Share Posted July 17, 2009 You should change or die ("could not execute query"); to or die('Invalid query: ' . mysql_error()); This will tell you the actual problem with your query. Link to comment https://forums.phpfreaks.com/topic/166349-cant-finish-log-in-page/#findComment-877269 Share on other sites More sharing options...
freddyw Posted July 17, 2009 Author Share Posted July 17, 2009 that wouldnt work as im not using mysql Link to comment https://forums.phpfreaks.com/topic/166349-cant-finish-log-in-page/#findComment-877279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.