+ Reply to Thread
Results 1 to 4 of 4

Thread: MySQL Problems

  1. #1
    tearsfall is offline x10Hosting Member tearsfall is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    7

    Exclamation MySQL Problems

    I made a premature guestbook for my site using PHP and MySQL. For some reason when I use the SELECT statement ... my first guestbook entry doesn't show, but all subsequent entries show.

    My site is:

    http://tearsfall.pcriot.com

    My guestbook is:

    http://tearsfall.pcriot.com/guestbook.php

    I'm using the mysql_escape_string() for the guestbook, for some reason it works without the escape string.

    Here is my guestbook.php code:

    Code:
    <html>
      <head>
        <title>Guestbook v1.061</title>
      </head>
    
      <body text="#000000">
    
      <p align="center">
        <table border="1" cellpadding="0" cellspacing="0" width="33%">
    
          <?php
          
            require "connect.php";
            
            $query = "SELECT * FROM guestbook";
            $result = mysql_query($query) or die(mysql_error());
                     
            if(mysql_fetch_array($result)=="") {
              echo "<tr rowspan='2'><td width='100%'>";
              echo "No entries.";
              echo "</td></tr>";
            }
            else {
           
              while($row = mysql_fetch_array($result)) {
                      
                echo "<tr><td width='100%' bgcolor='#666666'>";
                echo "<font color='#FFFFFF'><strong>&nbsp;&nbsp;&nbsp;";
                echo $row['messageID'] . " " . $row['guest_name'];
                echo "</strong></font>";
                echo "</td></tr>";
                
                echo "<tr><td width='100%' bgcolor='#999999'>";
                echo $row['message_post'];
                echo "</td></tr>";
              }
            }
           
           mysql_close($connection); 
           
          ?>
    
        </table>
      </p>
      <p align="center">
       Add to the guestbook. The current supported form is for guests. Registered users will eventually be supported.
      </p>
       <form id="guestbook" method="post" action="./guestbook_process.php">
         <p align="center">
          <table border="1" cellspacing="0" cellpadding="0" width="33%">
           <tr>
            <td align="center">Guest name: <input type="text" id="guest_name" name="guest_name" /></td>
           </tr>
           <tr>
            <td><textarea cols="38" rows="8" id="message_post" name="message_post"></textarea><br />255 Characters<br /><br /><input type="submit" id="submit" name="submit" value="Add" /> <input type="reset" id="reset" name="reset" value="clear" /></td>
           </tr>
          </table>
         </p>
        </form>
    
      </body>
    </html>
    here is my guestbook_process.php code:

    Code:
    <html>
      <head>
        <title>Adding to Guestbook</title>
    
        <script type="text/javascript">
        <!--
          function delayer()
            {
              window.location = "./guestbook.php"
            }
        //-->
        </script>
      </head>
    
      <body onLoad="setTimeout('delayer()', 1000)">
    
        <?php
    
          require "connect.php";
    
          $guest_name = mysql_escape_string($_POST['guest_name']);
          $message_post = mysql_escape_string($_POST['message_post']);
      
      
          if(empty($guest_name)||empty($message_post)) {
            die('One or more fields are missing to enter your record to our guestbook.');
          }
      
          $query = mysql_query("INSERT INTO 
                            guestbook(messageID,guest_name,message_post)
                            VALUES('','$guest_name','$message_post');");
                            
          echo "Thank you for adding to our guestbook.  You will be redirected to the guestbook page in 1 seconds.";
          
         mysql_close($connection);
         
        ?>
    
      </body>
    </html>
    My guestbook database is defined as follows

    guestbook(messageID,guest_name,message_post)

  2. #2
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: MySQL Problems

    check phpMyAdmin to see if there's any data in the fields. That'll tell us if it's when you try to select data, or when you try to insert it.

  3. #3
    tearsfall is offline x10Hosting Member tearsfall is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    7

    Re: MySQL Problems

    There is data in the fields. It's just simply not returning the first row when using the SELECT statement. Maybe there are invalid characters in my program from where I used notepad2 ... maybe I need to retype it or something?

  4. #4
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: MySQL Problems

    You are requesting the first row in your if statement:

    if(mysql_fetch_array($result)==""){

    Use instead:

    if(mysql_num_rows($result)<1){
    - When in doubt, refer to the PHP manual.

+ Reply to Thread

Similar Threads

  1. Joomla and MySQL
    By jtaah in forum Scripts & 3rd Party Apps
    Replies: 11
    Last Post: 04-10-2008, 06:28 PM
  2. MySQL Issues Here
    By Corey in forum Service Alerts
    Replies: 304
    Last Post: 01-06-2008, 09:10 PM
  3. MySQL Problems - Refreshing the cPanel Page
    By nyllo in forum Feedback and Suggestions
    Replies: 1
    Last Post: 12-24-2007, 01:07 AM
  4. in here MySQL version????
    By winUSD in forum Free Hosting
    Replies: 4
    Last Post: 05-09-2006, 08:44 AM
  5. mysql problems
    By NewFuture in forum Free Hosting
    Replies: 1
    Last Post: 06-26-2005, 10:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers