我真的很努力與這件pf php代碼,我想要插入一個消息到表中使用從另一個表中獲取的數據。下面是我的代碼:PHP/MySQL插入不工作
$get_user_sql = "SELECT username FROM members WHERE id = '$member'";
$get_user_res = mysqli_query($con, $get_user_sql);
while($username = mysqli_fetch_assoc($get_user_res)){
$user = $username["username"];
};
$get_message_sql = "SELECT message FROM posts WHERE id = '1377077348-5922'";
$get_message_res = mysqli_query($con, $get_message_sql);
while($postsmessage = mysqli_fetch_assoc($get_message_res)){
$postmessage = $postsmessage["message"];
};
$type = "liked";
$title = "New Like";
$message = "<a href=\"profile.php?member=$user\">$user</a> just liked your post:<br /><i>$postmessage</i>";
$insert_note_sql = "INSERT INTO notes (id, sender, recipient, type, title, message, date) VALUES('$id', '$member', '$recipient', '$type', '$title', '$message', '$time')";
$insert_note_res = mysqli_query($con, $insert_note_sql);
我發現,如果我從$消息行刪除$ PostMessage的一切工作正常,但是當我再次行添加回去未插入。任何人都可以看到這個原因嗎?
mysqli_error()說什麼?你是否迴應了查詢以確保它符合你的期望?你爲此做了哪些調試? –
您需要通過'mysqli_real_escape_string()' –
轉義您的所有數據查詢正在通過JQuery傳遞,所以我怎樣才能回顯錯誤呢? – user2516546