クエリを実行する前に、user_id 列の ptb_users というテーブルからユーザーが存在することを確認するように、mysql クエリに if ステートメントを追加しようとしています。
ユーザーは他のユーザーのウォールに書き込むことができ、ユーザーがユーザーのウォールに書き込む前に/クエリが ptb_wallposts に挿入される前に、from_user_id = ptb_users.user_id であることを確認したい。
私はこれをやろうとしていますが、ページ全体で構文エラーが発生します。これを構造化する方法を教えてください。
<?php
// check if the review form has been sent
if(isset($_POST['review_content']))
{
$content = $_POST['review_content'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
$content = stripslashes($content);
}
//We check if all the fields are filled
if($_POST['review_content']!='')
{
存在する場合 (user_id = @id である ptb_users から user_id を選択) 開始
{
$sql = "INSERT INTO ptb_wallposts (id, from_user_id, to_user_id, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$profile_id."', '".$content."');";
mysql_query($sql, $connection);
$_SESSION['message']="<div class=\"infobox-wallpost\"><strong>Wall Post Added</strong> - Your comment was posted to {$profile[2]}'s wall.</div><div class=\"infobox-close4\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
} }
}
end else begin echo "エラー ユーザーが存在しません" end
?>