我設法向評論表添加評論,但它不會顯示在相關文章中。我理解,因爲文章表中的外鍵(artID)是空的。如何從文章表中獲取主鍵?這是我的數據庫的結構。如何添加評論以發佈到Mysql和PHP
SQL注入問題將在稍後處理。準備好的陳述將完成。我只想獲得一些關於查詢和php函數的幫助。謝謝。
文章
artid的數據類型
artTitre
artAuteur
artContenu
artDate
住客評論
commentID
commentPseudo
commentText
artid的數據類型
commentaires.sql.php
<?php
// INSERT
function insertCommentaire($c){
$PseudoCommentaire = $TexteCommentaire ='';
$PseudoCommentaire = $_POST['PseudoCommentaire'];
$TexteCommentaire = $_POST['TexteCommentaire'];
$IdArticle = $_POST['IdArticle'];
$qryInsertComm = 'INSERT INTO commentaires (commentPseudo,commentText, artID)
VALUES (\''.$PseudoCommentaire.'\',
\''.$TexteCommentaire.'\',
\''.$IdArticle.'\')
';
if (!mysqli_query($c,$qryInsertComm))
{
die('Error: ' . mysqli_error($c));
}
echo "1 record added";
}
// UPDATE
function updateCommentaire($IdCommentaire){
}
// DELETE
function deleteCommentaire($IdCommentaire){
}
// CONTROLER //
switch($action){
case 'insert' :
$process = insertCommentaire($conn);
if($process == 'ok')
header('location:index.php?page=home');
else
$page = 'home';
break;
case 'update' :
$process = updateCommentaire($_GET[ 'item' ]);
if($process == 'ok')
header('location:index.php?page=home');
else
$page = 'home';
break;
case 'delete' :
$process = deleteCommentaire($_GET[ 'item' ]);
if($process == 'ok')
header('location:index.php?page=home');
break;
}
?>
這裏有很多代碼。請隔離該問題併發布相關代碼 –