【问题标题】:My php code is not working on postman when i insert parameters当我插入参数时,我的 php 代码在邮递员上不起作用
【发布时间】:2018-06-16 05:00:23
【问题描述】:

嘿,伙计们,我下面的 php 代码在邮递员上不起作用,每当我输入电子邮件和密码参数时,它都不起作用,并且只显示一个错误,它下面显示 {success:0 , message:invalid request},我我从数据库中给出正确的参数,我的数据库表名是用户,列是 id、name、email、password、type。请检查我在 php 中的新代码。请帮忙

    <?php header('Access-Control-Allow-Origin: *'); ?>
<?php header('Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type,Accept'); ?>
<?php header('Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT'); ?>
<?php 
 session_start();
include_once('configdb.php');
error_reporting(E_ALL);
$response = array();
if(isset($_POST['email']) && isset($_POST['password'])){
$name= $_POST['email'];
$password=$_POST['password'];
$result=mysqli_query($conn,"SELECT * FROM users WHERE email='$email' AND password='$password'");
 $row=mysqli_fetch_assoc($result);
 $count=mysqli_num_rows($result);
 if($count==1){
    $_SESSION['users']=array(
   'email'=>$row['email'],
   'password'=>$row['password'],
   'name'=>$row['name'],
   'type'=>$row['type']
   );
   $role=$_SESSION['users']['type'];
   //Redirecting User Based on Role
    switch($role){
  case 'user':
 // header('location:user.php');
  $response["success"] = 1;
   $response["message"] = "user.";
  break;
  case 'admin':
 // header('location:admin.php');
  $response["success"] = 1;
   $response["message"] = "admin.";
  break;
 }
 }else{
 $response["success"] = 0;
   $response["message"] = "PASSWORD OR EMAIL DOES NOT EXIST.";
 }
}
else{
$response["success"] = 0;
   $response["message"] = "INVALID REQUEST.";

}
header('Content-type: application/json');
  echo json_encode($response);
  mysqli_close($conn);

?>

你能告诉我错误是什么吗?

这是我的请求POSTMAN REQUEST

【问题讨论】:

  • 你能分享一下你在邮递员中提出的要求吗?

标签: php json postman


【解决方案1】:

您在查询中使用了$email 变量,但您将密码保存在$name 变量中。

【讨论】:

  • 谢谢,但你能告诉我为什么这段代码只是“用户”消息而不是管理员吗?
  • 因为管理员可能没有关联的电子邮件?或者它仍然保存在代码正在工作时的会话中。
猜你喜欢
  • 2018-08-07
  • 1970-01-01
  • 2015-01-02
  • 1970-01-01
  • 1970-01-01
  • 2017-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多