+ Reply to Thread
Results 1 to 5 of 5

Thread: PHP Writing to MySQL table Failure

  1. #1
    thomasross is offline x10Hosting Member thomasross is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    5

    PHP Writing to MySQL table Failure

    Ok, I am experiencing a problem where I get the following error:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/tross/public_html/Timetables/base_app_process.php on line 33
    Column count doesn't match value count at row 1
    The action which I am trying to do is take a name and e-mail address from a form on "base_list.php" and input it into a database using "base_app_process.php" so that I will be able to access the details to add to a mailing list manually. I am also using the "base_app_process.php" file to send a confirmation e-mail to the user and display a confirmation web-page.

    I am new to PHP, so sorry if any of the coding is messy.

    Any help would be gratefully recieved.

    Database Fields:
    "userid" int(11) auto_increment PRIMARY
    "name" varchar(60)
    "email_address" varchar(60)
    base_list.php

    I have erased part of this before the form section as it is just text and links in a table and not a part of the bit I am interested in - and I am over the character limit for this post.

    PHP Code:
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <?
    include 'header.html';
    ?>
    <html>
    <head>
    <title>FlyintAIR Crew Centre: Timetables: Home</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    table{font-family: Arial; color: #cc9933}
    -->
    </style>
    </head>
    <body>
    <form name="form1" method="post" action="base_app_process.php">
       <table border="0" cellpadding="10" cellspacing="0" align="center" width="60%" style="font-family: Arial;     font-size: 12pt; color: #cc9933"> 
        <tr> 
          <td  align="left" valign="top" style="color: black"><b><big><font face='Arial' color="blue">Join Timetable Update Mailing List</b></big></font><BR><BR>
    If you are using the PDF versions of our timetables, we ask that you submit your e-mail address to us so that we can contact you in the event of any updates to the timetable being necessary.  This will ensure that you are always up-to-date with the latest copy of the timetable and will therefore reduce the risk of submitting an invalid PIREP.  <br><br> 
    This mailing list is only valid for our "By-Base" PDF Timetables, if you wish for your details to be added to the "By-Aircraft" PDF Timetables mailing list, you must do this separately by clicking <a href="ac_list.php">here</a>.
           <br><br>
           You will receive an e-mail to confirm that your details have been received.  If you do not receive this, please e-mail your details and any error messages recieved to <a href="mailto:flyintair@gmail.com">flyintair@gmail.com</a>.</tr>
    </table>
    <table border="0" cellpadding="10" cellspacing="0" align="center" width="60%" style="font-family: Arial;     font-size: 11pt; color: #cc9933">
        <tr><center><BR><hr width=50%><BR></center></tr>
    <tr> 
          <td align="left" valign="top">Name</td>
          <td><input name="name" type="text" id="name" value=""></td>
        </tr>
        <tr> 
          <td align="left" valign="top">Email Address</td>
          <td><input name="email_address" type="text" id="email_address" value=""></td>
        </tr>
        <tr> 
          <td align="left" valign="top">&nbsp;</td>
          <td><input type="submit" name="Submit" value="Join Now!"></td>
        </tr>
      </table>
    </form>
    <table border="0" cellpadding="10" cellspacing="0" align="center" width="60%" style="font-family: Arial;     font-size: 10pt; color: #cc9933">
    <tr><hr width=100%><BR><BR></tr>
    <tr><b><big><font face = "Arial"><a href="timetable_index.php">Return to Timetable Centre Home</a></b></big><br></font></tr>
    <tr><BR><BR><hr width=100%><BR><BR></tr>
    <tr><font face="Arial"><b>If you have any questions or queries about any aspect of FlyintAIR - please do not hesitate to contact me and I will to my best to address these, e-mail me at <a href="mailto:flyintair@gmail.com">flyintair@gmail.com</a>
    </table>
    </body>
    </html>
    <? echo "<p>&nbsp;</p>";
     include 
    'footer.php';
    ?>
    base_app_process.php

    PHP Code:
    <?
    include 'db.php';
    // Define post fields into simple variables
    $name $_POST['name'];
    $email_address $_POST['email_address'];
     
    /* Do some error checking on the form posted fields */
    if((!$name) || (!$email_address)){
    echo 
    'You did not submit the following required information! <br />';
    if(!
    $name){
    echo 
    "Name is a required field. Please enter it below.<br />";
    }
    if(!
    $email_address){
    echo 
    "Email Address is a required field. Please enter it below.<br />";
    }
     
    include 
    'base_list.php'// Show the form again!
    /* End the error checking and if everything is ok, we'll move on to
    creating the user account */
    exit(); // if the error checking has failed, we'll exit the script!
    }
     
    /* Let's do some checking and ensure that the user's email address does not exist in the database */
     
    $sql_email_check mysql_query("SELECT email_address FROM times-base-update WHERE email_address='$email_address'");
     
     
    $email_check mysql_num_rows($sql_email_check);
     
    if(
    $email_check 0){
    echo 
    "<strong>Your email address is already on the mailing list!<br />";
    unset(
    $email_address);
     
    include 
    'base_list.php'// Show the form again!
    exit(); // exit the script so that we do not create this account!
    }
     
    /* Everything has passed the error check that we have done.*/
    // Enter info into the Database.
    $info2 htmlspecialchars($info);
    $sql mysql_query("INSERT INTO times_base_update (name, email_address) VALUES('$name', '$email_address', now())") or die (mysql_error());
    if(!
    $sql){
    echo 
    'There has been an error creating your account. Please contact the webmaster.';
    } else {
    $userid mysql_insert_id();
    // Let's mail the user!
    $subject "Timetable Update Mailing List!";
    $message "Dear $name,
     
    This e-mail is a confirmation that your e-mail address has now been successfully
    added to our mailing list.
     
    As part of this mailing list, you will receive updates any time that we update
    the PDF 'By-Base' timetables, allowing you to stay up-to-date with the latest
    copy of our timetable. As a member of this mailing list, you will NOT receive
    any e-mail updates regarding PDF 'By-Aircraft' or Web-based timetables. You 
    can subscribe to the PDF 'By-Aircraft' mailing list by visiting the page linked
    below:
     
    http://www.flyintair.x10hosting.com/Timetables/ac_list.php/
    If you did not submit your details to join this mailing list, would like your
    details removed from this list, or have any further questions - please e-mail
    me at flyintair@gmail.com or by using the Feedback/Contact form on the website.
     
    Happy Flying,
    Thomas Ross,
    CEO FlyintAIR Virtual Airlines
    http://www.spanglefish.com/intAIRnational/
     
    This is an automated response, please do not reply!"
    ;
     
    mail($email_address$subject$message"From: FlyintAIR VA <flyintair@gmail.com>\nX-Mailer: PHP/" phpversion());
    }
    mysql_close($connection);
    include 
    'header.html';
    ?>
    <html>
    <head><title>FlyintAIR Crew Centre: Mailing List Application Processed</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style="text/css">
    <!--
    body{font-family: Arial; color: #cc9933}
    -->
    </style>
    </head>
    <body>
    <table align="center" style="font-size: 12pt">
    <tr>
    </tr>
    <tr>
    <td align="center"><font face="Arial" color="blue"><b><big>Your application to join our PDF-Base Timetable Update Mailing List has been processed.</font></b></big></td>
    </tr>
    <tr>
    </tr>
    <tr>
    <td align="center"><font face="Arial" color="blue"><b>You should now recieve an e-mail confirming this.</font></b></td>
    </tr>
    <tr>
    <td align="center"><font face="Arial" color="blue"><b>Please be aware that the e-mail may be in your spam or junk e-mail folder.</b></font></td>
    </tr>
    <tr>
    <td align="center"><font face="Arial" color="blue"><b>If you do not receive this, please e-mail your details and any error messages recieved to <a href="mailto:flyintair@gmail.com">flyintair@gmail.com</a>./<b></td>
    </tr>
    <tr>
    <td align="center"><font face="Arial"><a href="base_list.php">Return to Base PDF Timetables</a></td>
    </tr>
    <tr>
    <td align="center"><font face="Arial"><a href="timetable_index.php">Return to Timetable Service Home</a></td>
    </tr>
    </table>
    </body>
    </html>
    If you need any more information to help me, just ask. Thanks in advance.

  2. #2
    supajason's Avatar
    supajason is offline x10 Lieutenant supajason is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    England........:-)
    Posts
    288

    Re: PHP Writing to MySQL table Failure

    ok i think you need to change:

    Code:
    $email_check = mysql_num_rows($sql_email_check);
     
    if($email_check > 0){
    with
    Code:
    if (mysql_num_rows($sql_email_check) > 0) {
    supajason was here

  3. #3
    thomasross is offline x10Hosting Member thomasross is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    5

    Re: PHP Writing to MySQL table Failure

    Quote Originally Posted by supajason View Post
    ok i think you need to change:

    Code:
    $email_check = mysql_num_rows($sql_email_check);
     
    if($email_check > 0){
    with
    Code:
    if (mysql_num_rows($sql_email_check) > 0) {
    Hi - thanks for your reply - but i am still getting the same error code using this.

    By my count (and from a previous error message I was getting before I made some slight alterations - sorry can't remember it - something to do with SQL manuals and syntax if that helps) I think the error must be somewhere around here:

    PHP Code:
    // Enter info into the Database.
    $info2 htmlspecialchars($info);
    $sql mysql_query("INSERT INTO times_base_update (name, email_address) VALUES('$name', '$email_address', now())") or die (mysql_error());
    if(!
    $sql){
     echo 
    'There has been an error creating your account. Please contact the webmaster.';
    } else {
     
    $userid mysql_insert_id(); 
    I can't understand why it would be in this area, as I have simply replaced the field names from a working bit of programming that I use in another part of my site. As I say I have been making changes based upon trial and error as I am new to PHP. I can post the working form and process if that helps in any way.

    As I say, any help or suggestions appreciated.

  4. #4
    sarvar's Avatar
    sarvar is offline x10Hosting Member sarvar is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    82

    Re: PHP Writing to MySQL table Failure

    You have an error here:

    PHP Code:
    $sql mysql_query("INSERT INTO times_base_update (name, email_address) VALUES('$name', '$email_address', now())") or die (mysql_error()); 
    You state that data will be inserted into two rows (forgot what to call it), one is 'name' other is 'email_address'.
    But you are inserting data into 3 rows. First data is 'name', second data is 'email_address' last one is timestamp. Try using this query instead.

    PHP Code:
    $sql mysql_query("INSERT INTO `times_base_update` (name, email_address) VALUES('".$name."', '".$email_address."')") or die (mysql_error()); 
    Last edited by sarvar; 01-22-2009 at 02:43 PM.
    CLICK HERE to Thank Me.
    (You must be logged in into forums.)

  5. #5
    thomasross is offline x10Hosting Member thomasross is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    5

    Re: PHP Writing to MySQL table Failure

    Quote Originally Posted by sarvar View Post
    You have an error here:

    PHP Code:
    $sql mysql_query("INSERT INTO times_base_update (name, email_address) VALUES('$name', '$email_address', now())") or die (mysql_error()); 
    You state that data will be inserted into two rows (forgot what to call it), one is 'name' other is 'email_address'.
    But you are inserting data into 3 rows. First data is 'name', second data is 'email_address' last one is timestamp. Try using this query instead.

    PHP Code:
    $sql mysql_query("INSERT INTO `times_base_update` (name, email_address) VALUES('".$name."', '".$email_address."')") or die (mysql_error()); 
    Thank you very much for your help. Working well now.

    Mods - couldn't find the thing to close threads in the Thread Tools section as per forum rules, sorry - please feel free to close as the issue is now resolved. Thanks.
    Last edited by thomasross; 01-22-2009 at 03:26 PM. Reason: Couldn't close thread.

+ Reply to Thread

Similar Threads

  1. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  2. check if mysql database table exists
    By daileyj2 in forum Programming Help
    Replies: 3
    Last Post: 08-14-2008, 08:21 PM
  3. PHP MYSQL photogallery table help
    By ncusa367 in forum Programming Help
    Replies: 1
    Last Post: 07-26-2008, 10:32 PM
  4. Mysql help needed: getting number of items in table column
    By xprtweb in forum Programming Help
    Replies: 1
    Last Post: 02-23-2008, 01:17 AM
  5. Php And Mysql Forum Rephrased!
    By maddude in forum Scripts & 3rd Party Apps
    Replies: 7
    Last Post: 04-05-2005, 12:14 PM

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