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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.