中的非對象我有以下錯誤,這與我用於註冊用戶的表單處理文件完全相同,但是我已將其更改爲相應的表和列。雖然每次都能正常工作。 這裏就是錯誤所在的代碼:調用成員函數execute()對
$sql = "INSERT INTO events1 (eventname,about,website) VALUES (:yas,:yasas,:yasasha)";
$q = $conn->prepare($sql);
$q->execute(array(':yas'=>$eventname,':yasas'=>$about,':yasasha'=>$website));
<?php
$servername = "localhost";
$username = "root";
$password = "Af2vaz93j68";
$dbname = "pdo_ret";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$eventname = $_POST['eventname'];
$about = $_POST['about'];
$website = $_POST['website'];
if($eventname == '') {
$errmsg_arr[] = 'You must enter your Email';
$errflag = true;
}
if($about == '') {
$errmsg_arr[] = 'You must enter your Password';
$errflag = true;
}
if($website == '') {
$errmsg_arr[] = 'You must enter First Name';
$errflag = true;
}
$sql = "INSERT INTO events1 (eventname,about,website) VALUES (:yas,:yasas,:yasasha)";
$q = $conn->prepare($sql);
$q->execute(array(':yas'=>$eventname,':yasas'=>$about,':yasasha'=>$website));
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
您是否檢查過連接是否失敗?另請向我們展示您的**全**代碼。所以如果有其他的錯誤,我們馬上看到它。 (在你的文件(S)的頂部添加錯誤報告:'',並告訴我們,如果你得到任何更多的錯誤 –
Rizier123
2015-02-07 15:15:51
是的,連接沒問題,我會更新代碼 – SARUAV 2015-02-07 15:16:49
什麼是錯誤信息?可能是某一列是必需的,但是你正試圖保存一個空字符串? – 2015-02-07 15:20:25