Jump to content

post request method


acap89

Recommended Posts

<?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.

Link to comment
https://forums.phpfreaks.com/topic/260975-post-request-method/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/260975-post-request-method/#findComment-1337502
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/260975-post-request-method/#findComment-1337504
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.