Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 33

Thread: comment area

  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts

    comment area

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/runningp/public_html/members/include/box.php on line 25

    PHP Code:
    <?php session_start();
        
    // Sign the guestbook
        
    require_once("../settings.php");
        {
           
    $id $_SESSION['user_id'];  

     
    $get_username_value get_username($id);

        
    $username $_GET['user'];
        
    $from $get_username_value;
        
        
    $message $_POST["message"];
        
    $time date("F j, Y, g:i a");
        
    $query "INSERT INTO guestbook(owner,postedby,post,time) VALUES('$username','$from','$message','$time')";
        
    $db->query($query);
        echo 
    "Your message has been posted";
        
     

    }

    $owner $get_username_value;
    $query $query "SELECT * FROM guestbook WHERE owner='$get_username_value' ORDER BY ID DESC"
    $result $db->query($query);
    while(
    $grab mysql_fetch_array($result))
        {
            echo 
    "Posted by: <a href=\"member.php?id=".$grab["postedby"]."\">".$grab["postedby"]."</a> - ".$grab["time"]."<br/>".$grab["post"]."<br><br>";
        }
    echo 
    "<center><br/><b>Sign $owner:s guestbook</b><br/>
    <form action=\"member.php?sign=$owner&from=$get_username_value method='POST'>
        <textarea name='message' rows='5' cols='30' align='left'>Your message</textarea><br/>
        <input type='submit' value='Update' name='submit'>
        </form>
    </center>"
    ;

    ?>
    basicly i cant undestand whats up with while($grab = mysql_fetch_array($result))
    {
    echo "Posted by: <a href=\"member.php?id=".$grab["postedby"]."\">".$grab["postedby"]."</a> - ".$grab["time"]."<br/>".$grab["post"]."<br><br>";
    } to fetch all the results for the comment area


    also if there is an easyer way of making a comment box for each profile im open to suggestions lol but this is the way iv thought about going about it

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/runningp/public_html/members/include/box.php on line 25
    Check your old threads to see the comments posted by other members on similar cases Or use google.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    hummm ok iv been thinkin ... if i got a normal shoutbox, how would i do it so each user has there own shoutbox?? asign each shoutbox with sum id in the db and call the id or something?>

  • #4
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Runnerjp, you really need to go back to the basics and read up on lots of tutorials. You're really missing simple things here, and although we love to help, it's getting a little out of control.

    Your code below:
    PHP Code:
    $query $query "SELECT * FROM guestbook WHERE owner='$get_username_value' ORDER BY ID DESC"
    $result $db->query($query);
    while(
    $grab mysql_fetch_array($result)) 
    Problems:
    1. That first line completely baffles me as to why you have that set up like you do. It should read:
      PHP Code:
      $query "SELECT * FROM guestbook WHERE owner='$get_username_value' ORDER BY ID DESC"
    2. Your second line is using some query method from probably a cross-DB class. It's not a mysql_query(), thus it will not return a MySQL result resource.


    If you are going to use this DB class you seem to be using, you cannot use PHP MySQL functions. However, if you want to use these PHP MySQL functions, then you must use the MySQL connect and query functions provided by PHP, i.e. mysql_connect() and mysql_query(), instead of $db->query().

    -Shane

  • #5
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    ok atting at from scratch and i have got an error im not famillia with

    PHP Code:
    <?php
    session_start
    (); // starts sessions

    $id $_SESSION['user_id'];
    $query "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1"
    if (
    $result mysql_query($query)){
        if (
    mysql_num_rows($result)) {
            
    $array mysql_fetch_assoc($result);
                   
    $message $array['message'];
                   }}



     echo 
    $message
     

     echo (
    " <form method='POST' action='?page=updatepost'>
    <table width="
    523" border="0" align="center" cellpadding="0" cellspacing="2">
    <tr><td width="
    150"><div align="right">
    <label for="
    events">Message</label>
    </div>
    </td>
    <td colspan="
    2"><textarea class="input" id="message" name="message" rows="4" cols="40">type your message here</textarea></td>
    </tr>
    <tr>
    <td width="
    150"></td>
    <td width="
    112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td>
    <td width="
    253">&nbsp;</td>
    </tr>
    </table>
    </form>"
    );
    case 
    'updatepost':
    $id $_POST['id'];
    $message $_POST['message'];
    $update "INSERT guestbook SET message='$message', id = '$id' WHERE id='$id' ";
    $rsUpdate mysql_query($update);
    if (
    $rsUpdate)?>
    unexpected T_LNUMBER on this line <table width="523" border="0" align="center" cellpadding="0" cellspacing="2">

  • #6
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    See, you're running into the same problems that I helped you with previously. You're not learning anything we're telling you.

    You are using double quotes in your HTML inside an echo that was started with double quotes. Instead of echoing all that HTML, just end your PHP before it and then start it back up when you need to.

    Like this:
    PHP Code:
    <?php
    session_start
    (); // starts sessions

    $id $_SESSION['user_id'];
    $query "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1"
    if (
    $result mysql_query($query)){
        if (
    mysql_num_rows($result)) {
            
    $array mysql_fetch_assoc($result);
                   
    $message $array['message'];
                   }}

     echo 
    $message
    ?>
    <form method='POST' action='?page=updatepost'>
    <table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
    <tr><td width="150"><div align="right">
    <label for="events">Message</label>
    </div>
    </td>
    <td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40">type your message here</textarea></td>
    </tr>
    <tr>
    <td width="150"></td>
    <td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td>
    <td width="253">&nbsp;</td>
    </tr>
    </table>
    </form>
    <?php
    case 'updatepost':
    $id $_POST['id'];
    $message $_POST['message'];
    $update "INSERT guestbook SET message='$message', id = '$id' WHERE id='$id' ";
    $rsUpdate mysql_query($update);
    if (
    $rsUpdate)?>
    As much as I didn't want to look at your code, I just can't help notice that there are many more errors in it.

    1. Your form doesn't even have an input that has name="id", so the line $id = $_POST['id] isn't going to retrieve anything. On top of that, you store the user_id from the session into $id, so there's no reason for this code anyway.
    2. Your update query needs UPDATE and not INSERT.
    3. In this post, you're actually using mysql_query(), where before, you were using $db->query. Which one is it?
    4. And last, you have a random case statement without the start of a switch statement.


    Seriously, you need to start going through tutorials on your own and learn much more before posting another 50 questions that all end up with similar errors.

    -Shane

  • #7
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    humm i dont think im using my switch statement properly

    PHP Code:
    <?php
    session_start
    (); // starts sessions

    $id $_SESSION['user_id'];
    $query "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1"
    if (
    $result mysql_query($query)){
        if (
    mysql_num_rows($result)) {
            
    $array mysql_fetch_assoc($result);
                   
    $message $array['message'];
                   



     echo 
    $message
     
    {switch(
    $_GET[page])}
    default:
     echo (
    ' <form method="POST" action="?page=updatepost">
    <table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
    <tr><td width="150"><div align="right">
    <label for="events">Message</label>
    </div>
    </td>
    <td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40">type your message here</textarea></td>
    </tr>
    <tr>
    <td width="150"></td>
    <td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td>
    <td width="253">&nbsp;</td>
    </tr>
    </table>
    </form>'
    );

    case 
    'updatepost':
    $id $_POST['id'];
    $message $_POST['message'];
    $update "INSERT guestbook SET message='$message', id = '$id' WHERE id='$id' ";
    $rsUpdate mysql_query($update);
    if (
    $rsUpdate)}}?>
    also im missing some {} out sum where but for the life of me can see where abouts

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by runnerjp View Post
    humm i dont think im using my switch statement properly


    also im missing some {} out sum where but for the life of me can see where abouts
    Then read http://in2.php.net/switch to get the proper syntax.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    do i even need to use switch in this case as all i need to do is post the data once forms submitted

  • #10
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    RunnerJP, stop coding. Start reading. Please. You have brackets ALL over the place for no reason. Your code looks like a word scramble where you seem to have the right letters, but they're all in the wrong places. The below code will fix all your errors you're having hopefully, but this is the last time I do this.
    PHP Code:
    <?php
    session_start
    (); // starts sessions

    $user_id $_SESSION['user_id'];

    if (isset(
    $_POST['update _submit']))
    {
        
    $post_id intval($_POST['post_id']);
        
    $message $_POST['message'];
        
    $update "UPDATE guestbook SET message = '".mysql_real_escape_string($message)."' WHERE id = $post_id ";
        
    $rsUpdate mysql_query($update);
    }

    $query "SELECT * FROM guestbook WHERE id = '$user_id' LIMIT 1"
    if (
    $result mysql_query($query))
    {
        while(
    $row mysql_fetch_assoc($result))
        {
            
    $post_id $row['id'];
            
    $message $row['message'];
        }
    }
    ?>
    <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
    <input type="hidden" name="update _submit" value="1" />
    <input type="hidden" name="post_id" value="<? if(isset($post_id)) echo $post_id?>" />
    <tr><td width="150"><div align="right">
    <label for="events">Message</label>
    </div>
    </td>
    <td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40">
    <?php 
        
    if(isset($message))
        {
            echo 
    $message
        }
        else
        {
            echo 
    "Type your message here";
        }
    ?>
    </textarea></td>
    </tr>
    <tr>
    <td width="150"></td>
    <td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td>
    <td width="253">&nbsp;</td>
    </tr>
    </table>
    </form>
    I tried my best, but you have a lot of stuff still missing, like the difference between the user's ID and post's ID and how it should be pulling the info. I also took a guess on where things should appear and how the page should work. Like I said above, please just stop coding for now and read some PHP tutorials. You need to wrap your head around the basic concepts before attempting a website like this.

    -Shane

  • #11
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    If you are stuck with the best place to start really learning PHP and MySQL I can really recommend this book.

    Beginning PHP and MySQL

    It will be well worth the money, whilst learning by jumping straight in can work, a book can teach you things like best practices, coding standards etc. Which just can not be self taught.

  • #12
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    The below code will fix all your errors you're having hopefully, but this is the last time I do this.
    Someone else will again.

    That is the problem with some of the helping going on here. It's more like spoonfeeding.

    I've suggested to several people before that they should start reading a book or taking a class. But they always come back with the same problems having learned nothing.

  • #13
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    ok i have progressed alot so far ... yes guys the books on its way but i have got some where with this now and its an error thats not small like synthax or anything

    but for some reaosn my code will not add the users username.. it leaves the field blank

    Code:

    PHP Code:
    <html>
    <head>
    <title>Shoutbox!</title>
    <style type="text/css">
    <!--
    .message {
    color: #000000;
    font-family: Verdana;
    font-size: 10px;}

    .username {
    color: #FF9900
    font-family: Verdana;
    font-size: 10px;
    font-weight: bold}

    .date {
    color: #707070;
    font-family: Verdana;
    font-size: 9px;}

    .forms {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10 px;
    color: #6CA05A;
    text-decoration: none;
    background-color: #CCCCCC;
    border-color: #6CA05A;
    border-style: solid;
    border: 1px}

    .submit {
    background-color: #CCCCCC;
    border-color: #6CA05A;
    color: #2A343C;
    font-family: Verdana;
    font-size: 10px;
    border-style: solid;
    border 1 px;}
    -->
    </style>
    </head>
    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="padding: 2px">
    <?php

    // If submitted
    if($_POST['submit']) {

    // Verify if the fields were filled.
    if(!$_POST['message']) {
    echo 
    'Error, You need to post a Message!';
    die;
    }

    // Date format
    $date date("d/m/y"); // http://www.php.net/date

    // Assign variables of the forms

    $id $_SESSION['user_id'];
    $username $id;
    $message $_POST['message'];
    $ip $_SERVER['REMOTE_ADDR'];

    // Connect to the database
    include('../../settings.php');

    // Insert the info in the shoutbox table.
    $query "INSERT INTO shoutbox ( username, message, date, ip)
    VALUES ('$username','$message','$date','$ip')"
    ;
    mysql_query($query);
    // close connection


    // Show message to let them return to the shoutbox
    ?>
    <div align="center">Thank you for submitting.<br>
    Return to the <a href="shoutbox.php">shoutbox</a>!
    <?php
    // If NOT submitted
    } else {




    $query "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 10";
    $result mysql_query($query);
    // Create a table
    ?>

    <table width="100%" cellpadding="0" cellspacing="0" border="0">

    <?
    // Run a While loop for the rows
    while($c mysql_fetch_array($result))
    {
    ?>
    <tr>
    <td>
    <? echo $c[author?></a> says:
    <div align="justify"><? echo $c[message?></div>
    </td>
    </tr>
    <tr><td>on <? echo $c[date?>
    <hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr>
    <? ?>

    </table>

    <form method="post" action="box.php">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td>Message :</td>
    <td><input type="text" name="message" class="forms"></td>
    </tr>
    <tr>
    <td colspan="2"><input type="submit" name="submit" value="Speak!" class="subtmit"></td>
    </tr>
    </table>
    </form>

    <?php ?>

    </body>
    </html>

    also i was wondering.. whats th best way to go now with assigning each user their own chatbox ??

    so on profile 1 it has chatbox 1 come up
    on profile 2 it has chatbox 2 ect ect

  • #14
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    ok i have found the problem... but i dont understand why its not working

    PHP Code:
    <? $id $_SESSION['user_id'];
    $username get_username($id);

    $message $_POST['message'];
    $ip $_SERVER['REMOTE_ADDR'];



    // Insert the info in the shoutbox table.
    $query "INSERT INTO shoutbox ( username, message, date, ip)
    VALUES ('$username','$message','$date','$ip')"
    ;
    mysql_query($query);?>
    its inserting the message date and ip... but not the username...

    if there something wrong with the way i have done $username = get_username($id);

  • #15
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    :O:O omg iv just relised....session_start();


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •