gpt4 book ai didi

php - 如何让插入查询与两个 if(isset 语句一起使用?

转载 作者:行者123 更新时间:2023-11-29 09:19:59 25 4
gpt4 key购买 nike

在用户个人资料上,有一个评论框,其他用户可以在其个人资料上发表评论。我现在正在开发一个动态评论区域,该区域具有不断变化的文本框,具体取决于 A. 您正在查看自己的个人资料 B. 查看别人的个人资料 C. 根本没有登录。

我现在正在尝试实现“更新”,当您在自己的页面上时,在评论框中输入内容,然后它会输出到页面上的指定区域。 (将在社区页面上输出它,但还没有)

在此配置文件页面上,我的插入查询可以很好地插入常规注释(第一个插入查询),现在我尝试使用第二个插入查询添加第二个 if(isset 语句,但执行此操作时遇到问题。

点击提交按钮后,它没有插入,页面加载为空白。顺便说一句,我是 php 的新手。谢谢:

    /* code chunk for the regular comments that is working just fine */

if(isset($_POST['commentProfileSubmit']) && $auth) {

$query = "SELECT `Email` FROM `Users` WHERE `id` = '" . $prof->id . "'";
$request = mysql_query($query,$connection) or die(mysql_error());
$result = mysql_fetch_array($request);

$Email = $result['Email'];


$to = $Email;
$subject = "$auth->first_name $auth->last_name left you a comment";
$message = "$auth->first_name $auth->last_name left you a comment: <br /><br /> <a href='http://www.blah.org/Profile.php?id=" . $prof->id . "'>Click here to view</a><br /><br />";
$from = "blah <noreply@blah.org>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $from";
mail($to, $subject, $message, $headers);



$query = "INSERT INTO `ProfileComments`
( `FromUserID`,
`ToUserID`,
`commentProfileBody`,
`status`,
`date`,
`time`

) VALUES (

'" . $auth->id ."',
'" . $prof->id ."',
'" . mysql_real_escape_string($_POST['ProfileComment']) ."',
'active',
'" . date("Y-m-d") . "',
'" . date("G:i:s") . "')";

mysql_query($query,$connection);

/* code chunk that is not inserting the desired info into the db and loading the page blank when I hit submit */

}elseif(isset($_POST['airwaveSubmit']) && $auth) {

$query2 = "INSERT INTO `Airwaves`
( `id`,
`body`,
`status`,
`date`,
`time`

) VALUES (

'" . $auth->id ."',
'" . $mysql_real_escape_string($_POST['body']) . "',
'active',
'" . date("Y-m-d") . "',
'" . date("G:i:s") . "')";

mysql_query($query,$connection);

}
?>

/* dynamic text/areas with dynamic submit buttons which is working how it should but want to include in case there is something on here that is causing the previous troubles */

<div id="commentBoxBlog">
<form name="CommentBox" method="post" action="Profile2.php?id=<?php echo $prof->id; ?>">
<?php if($auth->id == $prof->id) {
echo "<div id='counter'>
<span id='counter_airway'>140 Character Limit</span>
</div>";
echo "<textarea name='airwaveBody' class='round_10px' onkeyup='limit_length(this,140,\"counter_airway\");'></textarea> <input type='submit' name='airwaveSubmit' value='Exhale' class='post'/>";} elseif(!$auth) {
echo "<textarea name='ProfileComment' class='round_10px' disabled>Please sign in to comment...</textarea>"; } elseif($auth->id != $prof->id)
echo "<textarea name='ProfileComment' class='round_10px'></textarea>
<input type='submit' name='commentProfileSubmit' value='Exhale' class='post' />";

?>
</form>
</div>

最佳答案

您将 SQL 放入名为 $query2 的变量中,但在 mysql_query() 调用中将其发送到数据库时,您使用名为 $query 的变量。

关于php - 如何让插入查询与两个 if(isset 语句一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2328087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com