我有以下類方法的MySQL/PHP的插入查詢問題
public function index()
{
$username = '';
$email = '';
$text = '';
$picture = '';
if (isset($_POST['submit']))
{
$username = $_POST['username'];
$email = $_POST['email'];
$text = $_POST['text'];
$picture = $_POST['picture'];
Task::create($username, $email, $text, $picture);
}
require_once(ROOT.'/views/site/index.php');
}
我的形式發送值,我var_dump($_POST['username'])
這裏檢查是create()
方法
public static function create($username, $email, $text, $picture='1', $check_token=false)
{
$db = Db::connect();
$query = 'INSERT INTO tasks (username, email, text, picture, check_token)
VALUES (:username, :email, :text, :picture, :check_token)';
$result = $db->prepare($query);
$result->bindParam(':username', $username, PDO::PARAM_STR);
$result->bindParam(':email', $email, PDO::PARAM_STR);
$result->bindParam(':text', $text, PDO::PARAM_STR);
$result->bindParam(':picture', $picture, PDO::PARAM_STR);
$result->bindParam(':check_token', $check_token, PDO::PARAM_STR);
$result->execute();
}
我的數據庫連接正確導致我的認證系統起作用。但是這個查詢不會插入任何東西。我的代碼出了什麼問題? 感謝您的幫助。
任何錯誤返回或一切順利嗎? –
'stmt-> errorInfo()'函數 –
@HonzaRydrych有這樣的警告'注意:未定義索引:第21行的/home/hue/test/controllers/SiteController.php中的文本 注意:未定義索引:/ home中的圖片第22行的/hue/test/controllers/SiteController.php –