php mysql select query返回true但不能选择我自己插入的行以进行测试

时间:2016-02-19 11:42:44

标签: php mysql

我使用一个简单的选择来选择其电子邮件地址等于post贴出的地址的行的位置,但每次我使用num行检查它是否返回一行它返回0并移动else语句,手动输入一行连接表来测试查询,任何帮助请我一直检查线几个小时,将有助于得到一双新鲜的眼睛,也许iv一直在看屏幕太久我不能告诉区别,所以从桌子上喘息一下

继承我的桌子结构,以防我在这里遇到问题

DATA TABLE STRUCTURE

<?php
include $_SERVER['DOCUMENT_ROOT'].'connect_database';

session_start();

$supplier_name = $_SESSION['supplier_name'];
$supplier_email = $_SESSION['supplier_email'];
$supplier_id = $_SESSION['supplier_id'];

if(isset($_POST['client_email'])) {        
  $input = $_POST['client_email'];        
  $client_email_to_add = trim($input," ");    

  $add_client_query = "SELECT * FROM `connections` WHERE `client` = '$client_email_to_add'";
  $add_client_query_run = mysqli_query($connection,$add_client_query);

  if($add_client_query_run !== false){
        $num_rows =mysqli_num_rows($add_client_query_run);
        if($num_rows == 1) {
          header("location:dashboard_clients.php?response=".urlencode(" $client_email_to_add Client found")."&type=".urlencode(1));
        } else {
          header("location:dashboard_clients.php?response=".urlencode("$client_email_to_add Client was not found")."&type=".urlencode(0));
        }
  } else {
    echo "Query did not run";
  }
}
?>

1 个答案:

答案 0 :(得分:0)

编写如下代码: -

// include file by below way
include($_SERVER['DOCUMENT_ROOT'] . '/connect_database');
//$conn = mysqli_connect("localhost", "my_user", "my_password", "world");
session_start();

$supplier_name = $_SESSION['supplier_name'];
$supplier_email = $_SESSION['supplier_email'];
$supplier_id = $_SESSION['supplier_id'];


  if(isset($_POST['client_email'])){

      $input = $_POST['client_email'];

      $client_email_to_add = trim($input," ");    

      $add_client_query = "SELECT * FROM `connections` WHERE `client` = '$client_email_to_add'";

      $add_client_query_run = mysqli_query($connection,$add_client_query);

     // $add_client_query_run will returns True or False
     if($add_client_query_run){     
        // success
        header("location:dashboard_clients.php?response=".urlencode(" $client_email_to_add Client found")."&type=".urlencode(1));
        exit; // write exit after header to stop executuon of below code
     }
    else{
       // check query errors. assume your connection object is $conn
       printf("Errormessage: %s\n", mysqli_error($conn));
       //  echo "Query did not run";
        header("location:dashboard_clients.php?response=".urlencode("$client_email_to_add Client was not found")."&type=".urlencode(0));
        exit; // write exit after header to stop executuon of below code
  }
}

希望它会对你有所帮助:)。