如何修复MySQL返回一个空结果集(即零行)。 (查询耗时0.0014秒。)

时间:2017-02-04 05:40:37

标签: php mysql

<?php
             $con=mysqli_connect("localhost","root","") or die(mysql_error());
             $db=mysqli_select_db( $con,"registration") or die(mysql_error());
             if(isset($_POST['submit1'])){
                $t1=$_POST['t1']; 
                $t2=$_POST['t2']; 
                $t3=$_POST['t3']; 
                $t4=$_POST['t4']; 
                $r1=$_POST['r1']; 

                $query="INSERT INTO regtable(t1,t2,t3,t4,r1)VALUES ($t1,$t2,$t3,$t4,$r1)";
                if(mysqli_query($con,$query)){
                    echo "<script>alert('Your are successfully registered!')</script>";
                }
              }

           ?>

1 个答案:

答案 0 :(得分:1)

您使用的是错误的方法,而应使用

  $query="INSERT INTO regtable(t1,t2,t3,t4)VALUES (:t1, :t2, :t3, :t4)";
 $query->bindParam(':t1', $t1);
$query->bindParam(':t2', $t2);
$query->bindParam(':t3', $t3);
$query->bindParam(':t4', $t4);
$query->bindParam(':t5', $t5);
  $query->execute();