views:

50

answers:

1

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>
+1  A: 

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.

Dan Grossman
still is loading the page blank and not inserting. That is good to know though. Thanks
Ralph The Mouf