0

我是 mysql 查询的新手,只是无法将此 mysqli 语句插入 mysql。我的脚本设置或我的 $sql 有问题吗?(虽然我没有收到任何错误,只是没有插入)

    <?php

$login = "coolkidz";  //this line insets into username
$sname = "heyu";
$city = "beautiful";
$empass = "awesome";
$eusername = "what";
$mcode = "nice";


$sql = "INSERT INTO login(sname, city, empass, eusername, mcode, username) VALUES('$sname', '$city', '$empass', '$eusername', '$mcode', '$login')");

    $hostname_Database = "censored";
    $database_Database = "censored";
    $username_Database = "censored";
    $password_Database = "censored";

    $mysqli = new mysqli($hostname_Database, $username_Database, $password_Database, $database_Database); 
    if (mysqli_connect_errno()) {
       printf("Connect failed: %s\n", mysqli_connect_error());
       exit();
    }

    $result = $mysqli->query($sql);
    if (!$result) {
       printf("%s\n", $mysqli->error);
       exit();
    }
    ?>
4

2 回答 2

0

你有这一行:

$sql = "INSERT INTO login(sname, city, empass, eusername, mcode, username) VALUES('$sname', '$city', '$empass', '$eusername', '$mcode', '$login')");

尝试将其更改为以下内容:

$sql = "INSERT INTO login(`sname`, `city`, `empass`, `eusername`, `mcode`, `username`) VALUES('$sname', '$city', '$empass', '$eusername', '$mcode', '$login')";

注意列名处的`,

)你在行尾有一个到很多

于 2012-11-09T05:09:01.430 回答
0
Please update "..'$var'..." to  "..'" . $var . "'..." like ex:
=>
$sql = "INSERT INTO login(sname, city, empass, eusername, mcode, username) 
     VALUES('" . $sname . "', '" . $city . "', '" . $empass . "', '"
     . $eusername . "','" . $mcode . "', '" . $login . "')";
于 2012-11-09T05:11:42.020 回答