freddyw Posted July 19, 2009 Share Posted July 19, 2009 Im really not sure why I'm recieving this error. heres the code im working on <? $username = (isset($_POST['username']) ? pg_escape_string($_POST['username']) : ""; $password = (isset($_POST['password']) ? pg_escape_string($_POST['password']) : ""; $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "noreferer"; #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_query ($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> any ideas why im recieving the error. I checked the whole code and cant see a ; out of place anywhere. EDIT: i changed the short tag to <?php the html is now shoing up with the log in from. however once the details are entered, it switched to the php page and is just blank Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/ Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Which line? Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878061 Share on other sites More sharing options...
freddyw Posted July 19, 2009 Author Share Posted July 19, 2009 it was line 1. but as mentioned in the edit, that error message has gone and im left with a blank page. I checked the source code to see if there is any clues in there, but the source code is also blank. Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878063 Share on other sites More sharing options...
haku Posted July 19, 2009 Share Posted July 19, 2009 You are missing some brackets around your isset functions. Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878065 Share on other sites More sharing options...
freddyw Posted July 19, 2009 Author Share Posted July 19, 2009 Thanks. any chance you could be more specific? Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878068 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Take the first line. Start with the number 0. Each time you encounter a (, add 1, when you encounter ) subtract 1. If you don't end up with 0 again you are missing some Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878070 Share on other sites More sharing options...
freddyw Posted July 19, 2009 Author Share Posted July 19, 2009 Haha, thanks. just to confirm. Should it be... <? $username = (isset($_POST['username'])) ? pg_escape_string($_POST['username']) : ""; $password = (isset($_POST['password'])) ? pg_escape_string($_POST['password']) : ""; $referer = (isset($_SERVER['HTTP_REFERER'])) I think im right with the first 2 lines. Just the referer line im unsure of. Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878080 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Yeah same for all of them. By the way, you shouldn't use short tags. Use these instead: <?php Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878081 Share on other sites More sharing options...
freddyw Posted July 19, 2009 Author Share Posted July 19, 2009 Thanks. Thats cleared up the blank page. Sorry if I'm being a a pain but im now recieving this error. Parse error: syntax error, unexpected T_VARIABLE in /home2/webusers/07/344740/public_html/sporticket/login.php on line 4 <?php $username = (isset($_POST['username'])) ? pg_escape_string($_POST['username']) : ""; $password = (isset($_POST['password'])) ? pg_escape_string($_POST['password']) : ""; $referer = (isset($_SERVER['HTTP_REFERER'])) $_SERVER['HTTP_REFERER'] : "noreferer"; #this will make user return to login page if a field is left empty if ( ( !$username ) or (!$password) ) { header ( "location:$referer" ); exit(); } Id appreciate your help Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878085 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 You're missing the ? between the third ternary operator's conditional statement and "true" statement. Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878087 Share on other sites More sharing options...
freddyw Posted July 19, 2009 Author Share Posted July 19, 2009 Thanks. I'm new to PHP and I have no idea what you meant. sorry ~embarssed face~ Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878095 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 You have this statement: $referer = (isset($_SERVER['HTTP_REFERER'])) $_SERVER['HTTP_REFERER'] : "noreferer"; That should be: $referer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "noreferer"; Note that statements are only terminated by ; or ?>. Going to a new line doesn't mean it's a new statement. I would recommend reading Language Reference in the manual. Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878098 Share on other sites More sharing options...
freddyw Posted July 19, 2009 Author Share Posted July 19, 2009 I would recommend reading Language Reference in the manual. I will do thankyou Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878104 Share on other sites More sharing options...
freddyw Posted July 19, 2009 Author Share Posted July 19, 2009 I would love to click the solve to this topic. I thought u helped me to that point Daniel. I appreciate yor help so far. I'm greatful for it. The script is working, However im recieving "could not ececute query." I made a change to my original script, and still recieve the error. I changed line 15 to read $psql="select * from users where username =\"$username\" and password =\"$password\""; rather than $psql="select * from users where username =\"$username\" and password = password (\"$password\")"; and it still wont execute. Is this something obvious that I'm missing. Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878116 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Try to replace the or die() with or trigger_error(pg_last_error(), E_USER_ERROR); And then read the link in my signature regarding this. Quote Link to comment https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/#findComment-878145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.