1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Form not inserting into database

Discussion in 'PHP' started by reyfus, Jun 22, 2013.

  1. #1
    I have a simple post status page that works when posting the status, but I have tried to add a drop down menu so the user can select a category to filter the posts, but the category isn't posting in my mysql database.

    Here is the drop down code
    <div style="width: 200px;"><select id="category">
      <option selected value="">Select Category</option>
      <option value="Art">Art</option>
      <option value="Music">Music</option>
      <option value="Sport">Sport</option></select></div>
    PHP:
    And here is the entire code for the page

    <?php
    $status_ui = "";
    $statuslist = "";
    if($isOwner == "yes"){
        $status_ui = '<textarea id="statustext" onkeyup="statusMax(this,250)" placeholder="What&#38;#39;s new with you '.$u.'?"></textarea>';
        $status_ui .= '<button id="statusBtn" onclick="postToStatus(\'status_post\',\'a\',\''.$u.'\',\'statustext\')">Post</button>';
    } else if($isFriend == true && $log_username != $u){
        $status_ui = '<textarea id="statustext" onkeyup="statusMax(this,250)" placeholder="Hi '.$log_username.', say something to '.$u.'"></textarea>';
        $status_ui .= '<button id="statusBtn" onclick="postToStatus(\'status_post\',\'c\',\''.$u.'\',\'statustext\')">Post</button>';
    }
    ?><?php
    $sql = "SELECT s.*, u.avatar
            FROM status AS s
            LEFT JOIN users AS u ON u.username = s.author
            WHERE (s.account_name = '$u' AND s.type='a')
            OR (s.account_name= '$u' AND s.type='c')
            ORDER BY s.postdate DESC LIMIT 20";
     
    $query = mysqli_query($db_conx, $sql);
    $statusnumrows = mysqli_num_rows($query);
    while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
        $statusid = $row["id"];
        $account_name = $row["account_name"];
        $author = $row["author"];
        $postdate = $row["postdate"];
    //
        $avatar = $row["avatar"];
        $user_image = '<img src="user/'.$author.'/'.$avatar.'" width="50" height="50" border="0">';
    //
        $category = $row["category"];
        $data = $row["data"];
        $data = nl2br($data);
        $data = str_replace("&amp;","&",$data);
        $data = stripslashes($data);
        $statusDeleteButton = '';
        if($author == $log_username || $account_name == $log_username ){
            $statusDeleteButton = '<span id="sdb_'.$statusid.'"><a href="#" onclick="return false;" onmousedown="deleteStatus(\''.$statusid.'\',\'status_'.$statusid.'\');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span> &nbsp; &nbsp;';
        }
        // GATHER UP ANY STATUS REPLIES
        $status_replies = "";
        $sql2 = "SELECT s.*, u.avatar
            FROM status AS s
            LEFT JOIN users AS u ON u.username = s.author
            WHERE s.osid = '$statusid'
            AND s.type= 'b'
            ORDER BY postdate ASC";
     
        $query_replies = mysqli_query($db_conx, $sql2);           
        $replynumrows = mysqli_num_rows($query_replies);
        if($replynumrows > 0){
            while ($row2 = mysqli_fetch_array($query_replies, MYSQLI_ASSOC)) {
                $statusreplyid = $row2["id"];
                $replyauthor = $row2["author"];
                $replydata = $row2["data"];
    //
                $avatar2 = $row2["avatar"];
                $user_image2 = '<img src="user/'.$replyauthor.'/'.$avatar2.'" width="50" height="50" border="0">';
    //
                $replydata = nl2br($replydata);
                $replypostdate = $row2["postdate"];
                $replydata = str_replace("&amp;","&",$replydata);
                $replydata = stripslashes($replydata);
                $replyDeleteButton = '';
                if($replyauthor == $log_username || $account_name == $log_username ){
                    $replyDeleteButton = '<span id="srdb_'.$statusreplyid.'"><a href="#" onclick="return false;" onmousedown="deleteReply(\''.$statusreplyid.'\',\'reply_'.$statusreplyid.'\');" title="DELETE THIS COMMENT">remove</a></span>';
                }
                $status_replies .= '<div id="reply_'.$statusreplyid.'" class="reply_boxes"><div><b>Reply by <a href="user.php?u='.$replyauthor.'">'.$replyauthor.'</a> '.$replypostdate.':</b> '.$replyDeleteButton.'<br /> <div style="width: 60px; float: left;">'.$user_image2.'</div><div>'.$replydata.'</div></div></div>';
            }
        }
        $statuslist .= '<div id="status_'.$statusid.'" class="status_boxes"><div style="width: 100%"><b>Posted by <a href="user.php?u='.$author.'">'.$author.'</a> '.$postdate.':</b> '.$statusDeleteButton.' <br /> <div style="width: 60px; float: left;">'.$user_image.'</div><div>'.$data.'</div></div>'.$status_replies.'</div>';
        if($isFriend == true || $log_username == $u){
            $statuslist .= '<textarea id="replytext_'.$statusid.'" class="replytext" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea><button id="replyBtn_'.$statusid.'" onclick="replyToStatus('.$statusid.',\''.$u.'\',\'replytext_'.$statusid.'\',this)">Reply</button>';   
        }
    }
    ?>
    <div id="statusui">
      <div style="width: 200px;"><select id="category">
      <option selected value="">Select Category</option>
      <option value="Art">Art</option>
      <option value="Music">Music</option>
      <option value="Sport">Sport</option></select></div><?php echo $status_ui; ?>
    </div>
    <div id="statusarea">
      <?php echo $statuslist; ?>
    </div>
    PHP:
    Thanks any help appreciated, I am still learning this >_<
     
    reyfus, Jun 22, 2013 IP
  2. qtriangle

    qtriangle Active Member

    Messages:
    179
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #2
    You need to have a <form> element and then post the contents of this form to the php script so that it can be saved.
    More Info: http://www.w3schools.com/html/html_forms.asp
     
    qtriangle, Jun 23, 2013 IP
  3. reyfus

    reyfus Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #3
    thanks for the reply, I'm just a little confused as the rest of the site doesn't have 1 <form> element but works fine.

    i.e.

    <?php
    $status_ui = "";
    $statuslist = "";
    if($isOwner == "yes"){
        $status_ui = '<textarea id="statustext" onkeyup="statusMax(this,250)" placeholder="What&#39;s new with you '.$u.'?"></textarea>';
        $status_ui .= '<button id="statusBtn" onclick="postToStatus(\'status_post\',\'a\',\''.$u.'\',\'statustext\')">Post</button>';
    } else if($isFriend == true && $log_username != $u){
        $status_ui = '<textarea id="statustext" onkeyup="statusMax(this,250)" placeholder="Hi '.$log_username.', say something to '.$u.'"></textarea>';
        $status_ui .= '<button id="statusBtn" onclick="postToStatus(\'status_post\',\'c\',\''.$u.'\',\'statustext\')">Post</button>';
    }
    ?>
    PHP:
     
    reyfus, Jun 23, 2013 IP
  4. qtriangle

    qtriangle Active Member

    Messages:
    179
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #4
    It has a post button that is posting all data for processing on button click. See definition of PostToStatus function, you will understand.
     
    qtriangle, Jun 24, 2013 IP
  5. hellz_guy

    hellz_guy Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #5
    recommend me best way to learn php?
     
    hellz_guy, Jun 25, 2013 IP
  6. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #6
    ActiveFrost, Jun 25, 2013 IP
    ryan_uk likes this.