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.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    Data not being stored/selected

    Here is my page... www.inthedesigns.net/comment.php

    When I go to test my comment form, it successfully submits, but the information doesn't get stored in the table or displayed on my page. I'm not sure what coding you would need me to give you to help, but this is so irritating.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The comment is getting created, because the number of blank comments increases as you add, so the problem is probably either the comment being inserted is blank for some reason or the mechanism that displays the comments isn't properly echoing the data from the table.

    Can't help without seeing the code of course....

  • #3
    Regular Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Fumigator View Post
    The comment is getting created, because the number of blank comments increases as you add, so the problem is probably either the comment being inserted is blank for some reason or the mechanism that displays the comments isn't properly echoing the data from the table.

    Can't help without seeing the code of course....
    Here is the code on my first page which contains the posts and then the form to fill it out.

    Code:
    <h1>View Comments</h1>
    
    <?php
    
    include("connect.php"); 
    
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);
    
    while($rows=mysql_fetch_array($result)){
    ?>
    
    <p>Posted by <a href="mailto:<? echo $rows['email']; ?>"><? echo $rows['name']; ?></a> on <? echo $rows['datetime']; ?>
    <br/>Comment: <? echo $rows['comment']; ?></p>
    
    <?
    }
    mysql_close(); //close database
    ?>
    
    <h1>Post a Comment</h1>
    
    <form id="form1" name="form1" method="post" action="addcomment.php">
    
    <div class="center">
    <strong>Name:</strong>
    <br/><input name="name" type="text" id="name" size="25"/>
    
    <p><strong>Email Address:</strong>
    <br/><input name="email" type="text" id="email" size="25"/></p>
    
    <p><strong>Comment:</strong>
    <br/><textarea name="comment" cols="35" rows="5" id="comment"></textarea></p>
    
    <p><input type="submit" class="button" value=" Post Comment "/></p>
    </div>
    </form>
    And here is the code for the addcomment.php page.

    Code:
    <?php
    
    include("connect.php"); 
    
    $datetime=date("l, F jS  g:i  A"); //date time
    
    $sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
    $result=mysql_query($sql);
    
    //check if query successful 
    if($result){
    echo "Your post has successfully been submitted.";
    echo "<BR>";
    echo "<a href='comment.php'>View Comments</a>"; // link to view guestbook page 
    }
    
    else {
    echo "ERROR";
    }
    
    mysql_close();
    ?>

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Do your variables $name, $email, etc, contain values?

  • #5
    Regular Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Like within the database table? Or in the form?

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Like at the point your script uses those variables to insert a row into your database. Use echo to find out.

  • #7
    Regular Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    In the first code I gave you it says

    Code:
    <p>Posted by <a href="mailto:<? echo $rows['email']; ?>"><? echo $rows['name']; ?></a> on <? echo $rows['datetime']; ?>
    <br/>Comment: <? echo $rows['comment']; ?></p>
    Like that?

  • #8
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Like add

    PHP Code:
    echo $name;
    echo 
    $email;
    etc..... 
    Right before the Insert statement. This is a basic debugging technique. If you find out there are no values in these variables, you've found your problem, and then you just need to find out why there are no values in these variables. You basically debug one step at a time, discovering a little bit of information at each step that leads to what the next step must be, like bread crumbs in a forest, eventually bringin you to a solution.

  • #9
    Regular Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    That didn't work. :[

  • #10
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    It's not meant to fix the problem, it's meant to give you enough information about the problem to find the solution, or at least the next step in finding the solution.

    If your variables $name and $email are empty, then that's exactly what's being inserted into your table. So did you find out if they are empty? Yes?

    Now you've got to find out why they are empty. Where are you putting values into them? Are you assuming register_globals is turned on? If so, is register_globals actually turned on?

  • #11
    Regular Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Register globals is turned off. Should I turn it on?

  • #12
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,132
    Thanks
    2
    Thanked 328 Times in 320 Posts
    No. Don't turn register globals on. They were turned off in php4.2 in the year 2002 because they were the greatest security blunder ever deliberately added to a programming language and they have been completely eliminated in upcoming php6. No new code, new books, new tutorials, or new hosting accounts should have been created after 2002 that relied on register globals or turned them on and all code that is dependent on register globals will stop working under php6.

    What Fumigator was trying to get you to realize is that the code you posted is not specifically setting the program variables $name, $email, and $comment that are being used in the INSERT query, which is why empty values are being inserted and displayed. The posted code is dependent on register_globals being on to "magically" populate program variables from GET/POST/COOKIE/SESSION variables. (Register_globals also allow SESSION variables to be "magically" set to any value a hacker wants by sending your script GET/POST/COOKIE values using the same name as a session variable.)

    You need to set the variables $name, $email, and $comment from the equivalent $_POST variables. You also need to validate what is in them (are they empty, do they contain bad content...) and escape what is in them using mysql_real_escape_string() to prevent sql injection.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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