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

发布于 2024-08-23 00:31:49 字数 4191 浏览 12 评论 0原文

在用户个人资料上,有一个评论框,其他用户可以在其个人资料上发表评论。我现在正在开发一个动态评论区域,该区域有一个不断变化的文本框,具体取决于是否 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 <[email protected]>";
       $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>

On a users profile, there is a comment box that enables other users to post comments on their profile. I am now working on a dynamic comment area that has a changing text box depending on if A. you are looking at your own profile B. looking at someone elses profile C. not signed in at all.

I am trying to implement "updates" now when you are on your own page, type in the comment box, and it outputs in a designated area on your page. ( going to have it output on a community page but not there yet)

On this profile page, I have the insert query that is inserting regular comments just fine (the first insert query) and now am trying to add a second if(isset statement with a second insert query and am having trouble doing this.

It is not inserting and the page is loading blank after the submit button is hit. I am a newbie with php btw. Thank you:

    /* 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 <[email protected]>";
       $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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一指流沙 2024-08-30 00:31:49

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

You put the SQL in a variable named $query2, but in your mysql_query() call to send it to the database you use a variable named $query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文