我在我的Mysqli插入這裏有一點問題。我在插入的周圍放置了一個try塊來捕捉可能的錯誤,我收到了它的工作通知,但沒有插入任何數據。Mysqli插入不起作用。沒有錯誤彈出
下面的代碼:
$mysqli = new mysqli("localhost", "yourusername", "somepasswdhere", "users");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
//formular set ?
if(isset($_POST['submit'])) {
echo $_POST['username'];
//bind post variables on local vars.
$username = $_POST['username'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
// Heres some crap but thats not that problem so im getting
// right into the next
// maybe problem part
try{
$mysqli->query("INSERT INTO `users` ($username) VALUES ('$username')");
$mysqli->commit();
echo "works";
} catch(Exception $e) {
echo $e->getMessage(), "\n";
}
要確保我的代碼將被提交,我把$mysqli->commit();
類似於INSERT INTO用戶(bob)VALUES('bob')'聽起來不正確。 – apokryfos