MySQL查询无法运行

时间:2017-05-30 23:16:41

标签: php mysql sql

INSERT INTO没有运行,除了通知$ re未定义外,我没有收到任何错误。它以前有效,但不再有效。

 $servername = "localhost";
 $username = "id728908_njaohnt";
 $password = "pass";
 $dbname = "id728908_sub";

 // Create connection
 $conn = new mysqli($servername, $username, $password, $dbname);
 // Check connection
 if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
 } 
 if (!$resu=$conn->query("SELECT confirmed FROM subscribers WHERE 
 email='".$email."'"))
 {echo $conn->error;}

 while ($row = $resu->fetch_assoc()) {
 $resul=$row['confirmed'];}
 $sql = "INSERT INTO subscribers (email) VALUES ('".$email."')";

    if ($resul==null || $resul==0)
    {
  if ($resul!=0)
{
    if ($conn->query($sql) === TRUE)
     {
 $res=$conn->query("SELECT A_I FROM subscribers WHERE email='".$email."'");
 while ($row = $res->fetch_assoc()) {
 $re=$row['A_I'];
...

$ email是      $ email = @trim(stripslashes($ _ GET ['email']));

1 个答案:

答案 0 :(得分:1)

$ email定义在哪里?如果是用户输入的,那么确保在将其放入SQL字符串之前对其进行清理。

重构:

 if ($resul==null || $resul==0)
 {
     if ($resul!=0)
     {

到此:

 if ($resul==null) {

其他条件没用。

在“$ re = $ row ['A_I'];”这一行上发生了“$ re is undefined”的消息?