acap89 Posted April 15, 2012 Share Posted April 15, 2012 <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ $db = mysql_connect("localhost", "*******" , "*****")or die("Error connecting to database: " . mysql_error()); $db_used = mysql_select_db("pskkorg_drp1", $db)or die("Could not select database: " . mysql_error()); $user_name = mysql_real_escape_string($_POST['username'],$db); $query = mysql_query("SELECT * FROM student WHERE Username = '$user_name'",$db) or die(mysql_error()); if(mysql_num_rows($query) == 1){ echo "Login successful, welcome back " . $user_name . ""; }else{ echo "Login unsuccessful, please ensure you are using the correct details"; } }else{ echo "Error"; } ?> take a look at this code, is there anything wrong?... it always come out the error output when i test it. when i enter this url, http://www.pskk.org/LMS/LMSscripts/FirstTimeUser10.php?Username=149090 it come out Error. suppose it will appear Login Successful since the username 149090 exist in the database. Quote Link to comment https://forums.phpfreaks.com/topic/260975-post-request-method/ Share on other sites More sharing options...
trq Posted April 15, 2012 Share Posted April 15, 2012 Appending data to a url shows up in $_GET not $_POST. Quote Link to comment https://forums.phpfreaks.com/topic/260975-post-request-method/#findComment-1337501 Share on other sites More sharing options...
Andy-H Posted April 15, 2012 Share Posted April 15, 2012 Because you are passing variables through the URL, so the request method is GET, and your code clearly says, if request method is POST, run code else echo error. You need to post the data via a form: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ $db = mysql_connect("localhost", "*******" , "*****")or die("Error connecting to database: " . mysql_error()); $db_used = mysql_select_db("pskkorg_drp1", $db)or die("Could not select database: " . mysql_error()); $user_name = mysql_real_escape_string($_POST['username'],$db); $query = mysql_query("SELECT * FROM student WHERE Username = '$user_name'",$db) or die(mysql_error()); if(mysql_num_rows($query) == 1){ echo "Login successful, welcome back " . $user_name . ""; }else{ echo "Login unsuccessful, please ensure you are using the correct details"; } }else{ echo "Error"; } ?> <form action="" method="post"> <input type="text" name="username" ><br > <input type="submit" name="submit" > </form> Quote Link to comment https://forums.phpfreaks.com/topic/260975-post-request-method/#findComment-1337502 Share on other sites More sharing options...
acap89 Posted April 15, 2012 Author Share Posted April 15, 2012 owh... then, when we can use POST method?... can elaborate more? Quote Link to comment https://forums.phpfreaks.com/topic/260975-post-request-method/#findComment-1337503 Share on other sites More sharing options...
acap89 Posted April 15, 2012 Author Share Posted April 15, 2012 i already replace POSR with GET. it appear - Login unsuccessful, please ensure you are using the correct details Im doing the android project that need the login page... the user will key in their username in the apps and the username will go to this php code in the server. Quote Link to comment https://forums.phpfreaks.com/topic/260975-post-request-method/#findComment-1337504 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.