![](/img/trans.png)
[英]How can I make this PDO mysql query with if statements work correctly?
[英]How can I get insert query to work with two if(isset statements?
在用户个人资料上,有一个注释框,使其他用户可以在他们的个人资料上发表评论。 我现在正在处理一个动态注释区域,该区域具有一个变化的文本框,具体取决于A.您是否在查看自己的个人资料B.在其他人的个人资料C.根本未登录。
当您在自己的页面上时,我现在尝试实现“更新”,在注释框中键入内容,并在页面的指定区域中输出。 (将其输出到社区页面上,但尚未输出)
在此配置文件页面上,我有一个插入查询,该插入查询可以很好地插入常规注释(第一个插入查询),现在正尝试添加第二个if(isset语句和第二个插入查询,这样做很麻烦。
点击提交按钮后,它没有插入并且页面正在加载空白。 我是php btw的新手。 谢谢:
/* 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的变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.