0

在我的 MYSQL 表中插入记录时遇到了一个小问题。数据正常,但是当代码查询以查看是否已输入时,我不断收到错误消息。

$sql = mysqli_query($connect,"INSERT INTO testtable (fnhusband,fnwife,surname,email,address,suburb,city,postcode,region,number,altnumber)
VALUES ('$fnhusband','$fnwife','$surname','$email','$address','$suburb','$city','$postcode','$region','$number','$altnumber')");

if (!mysqli_query($connect,$sql))
  {
  die('Error:' . mysqli_error());
  }
else { 
    echo "1 record added";
    mysqli_close($connect);
    }
4

1 回答 1

2

假设 $connect 是链接:

$connect = new mysqli("localhost", "my_user", "my_password", "world");

尝试改变

$sql = mysqli_query($connect,"INSERT INTO testtable (fnhusband,fnwife,surname,email,address,suburb,city,postcode,region,number,altnumber)
VALUES ('$fnhusband','$fnwife','$surname','$email','$address','$suburb','$city','$postcode','$region','$number','$altnumber')");
$result = mysqli_query($connect,$sql);

到:

$sql = "INSERT INTO testtable (fnhusband,fnwife,surname,email,address,suburb,city,postcode,region,number,altnumber)
VALUES ('$fnhusband','$fnwife','$surname','$email','$address','$suburb','$city','$postcode','$region','$number','$altnumber')";
$result = $connect->query($sql);

或程序:

$sql = "INSERT INTO testtable (fnhusband,fnwife,surname,email,address,suburb,city,postcode,region,number,altnumber)
VALUES ('$fnhusband','$fnwife','$surname','$email','$address','$suburb','$city','$postcode','$region','$number','$altnumber')";
$result = mysqli_query($connect, $sql);
于 2013-03-07T00:23:39.847 回答