如何使用插入查询来处理两个if(isset语句?

时间:2010-02-24 17:35:02

标签: php mysql insert isset

在用户个人资料中,有一个评论框,可让其他用户在其个人资料上发表评论。我现在正在开发一个动态评论区域,其中有一个更改的文本框,具体取决于是否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>

1 个答案:

答案 0 :(得分:2)

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