我在我的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