我正在嘗試在 php 中創(chuàng)建一個類似于 instagram 和 twitter 的 ajax 收藏夾按鈕。我的代碼似乎沒問題,我做的一切都正確,并試圖讓它以這種方式工作:PHP代碼: $user_id = $_SESSION['active_user_id']; extract($_POST); extract($_GET); if(isset($_GET['message'])) { $id=$_GET['message']; $q=$db->prepare("SELECT msgid,date,text FROM messages WHERE to_id=? and msgid=?"); $q->bindValue(1,$user_id); $q->bindValue(2,$id); $q->execute(); $row2=$q->fetch(); $d=$row2['date']; $fav_questionq=$db->prepare("SELECT * FROM messages LEFT JOIN users ON messages.to_id=users.id WHERE users.id=? AND messages.msgid=? "); $fav_questionq->bindValue(1,$user_id); $fav_questionq->bindValue(2,$id); $fav_questionq->execute(); $frow=$fav_questionq->fetch(); $fquestion= $frow['text']; $result = $db->prepare("SELECT * FROM fav_messages WHERE username=? AND message=?"); $result-bindValue(1,$user_id); $result-bindValue(2,$id); $result->execute(); if($result->rowCount()== 1 ) { $deletequery=$db->prepare("DELETE FROM fav_messages WHERE message=?"); $deletequery->bindValue(1,$id); $deletequery->execute(); echo("<script>location.href = 'index.php?a=recieved';</script>"); }但我一直在控制臺中收到錯誤消息:“Uncaught TypeError: Cannot read property 'value' of undefined at ajaxfav”但我已經(jīng)修復了它,現(xiàn)在它立即轉(zhuǎn)到警報消息,但沒有任何內(nèi)容被插入到數(shù)據(jù)庫中,這意味著數(shù)據(jù)沒有被發(fā)送到 php 文件. 有人可以告訴我我能做什么嗎? ajax 調(diào)用的網(wǎng)絡選項卡如果有任何幫助或建議,我將不勝感激。調(diào)用了 php 文件,但沒有向數(shù)據(jù)庫中插入任何內(nèi)容。
1 回答

慕工程0101907
TA貢獻1887條經(jīng)驗 獲得超5個贊
您可以使用 document.msgidform.elements['fav_message'].value
在您的 ajaxfav() 函數(shù)中獲取名稱字段值。
- 1 回答
- 0 關注
- 117 瀏覽
添加回答
舉報
0/150
提交
取消