当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Post method always returns nothing

问题描述:

I'm trying to check if the given information is correct with PHP and MySQL ! (for android project) but when I send them and I try to use the POST method and compare them in my database the POST method always returns that there is no information have been sent.

so this is my code :

<?php

$mysqli = new mysqli("localhost", "root", "", "hochschule");

/* verify connection */

if (mysqli_connect_errno()) {

printf("connection failed : %s\n", mysqli_connect_error());

exit();

}

/* recover data */

$benutzername = $mysqli->real_escape_string(isset($_POST['PARAM_LOGIN']));

$passwort = $mysqli->real_escape_string(isset($_POST['PARAM_PASSWORT']));

$result = $mysqli->query("SELECT COUNT(*) FROM user WHERE benutzername ='$benutzername' AND passwort='$passwort'");

$row = $result->fetch_row();

if($row[0] !=0) {

printf("true");

}else

printf("false");

/* Closing the connection */

$mysqli->close();

?>

I use PHP 5.6 and MYSQL 5.7 and I used DHC plugin in google chrome to test the PHP script.

NOTE :

I think it's a problem of compatibility because i'm using PHP 5.6 and MYSQL 5.7 and this code i used it for earlier project and with earlier versions of PHP (5.5) and MYSQL (5.6) and it worked fine back then.

Thank you for your help.

网友答案:

Problem is that isset just returns a boolean value (true or false) - not the value of the parameter.

So you want something like this:

/* recover data */
$benutzername = null;
$passwort = null;

if(isset($_POST['PARAM_LOGIN'])) 
    $benutzername =$mysqli->real_escape_string($_POST['PARAM_LOGIN']);
if(isset($_POST['PARAM_PASSWORT'])
    $passwort = $mysqli->real_escape_string($_POST['PARAM_PASSWORT']);
分享给朋友:
您可能感兴趣的文章:
随机阅读: