Hello, I am relatively new to php so be gentle. 🆒
I had a form that was working - ie. on submit it entered the form data into my database table and directed the user to a confirmation page.
Now, I have tried the same code again, and on submit I am getting an "Error query was empty" on my confirmation page (instead of the template I designed as a "Thank You for you information" page). However, the form data IS getting inputted into the database correctly. what am I missing?! HELP please....😕

Here is the php code on the adapply_submit.php page: (ie. my submit_form.php code)
<?php
$con = mysql_connect("myhost","user","pw");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("mydb", $con);

$fullname = $POST['fullname'];
$email = $
POST['email'];
$companyname = $POST['companyname'];
$companywebsite = $
POST['companywebsite'];
$adspace = $POST['adspace'];
$length = $
POST['length'];
$howlong = $POST['howlong'];
$adcreation = $
POST['adcreation'];
$adtype = $POST['adtype'];
$addons = $
POST['addons'];
mysql_query("INSERT INTO gmradapply2009 (fullname, email, companyname, companywebsite, adspace, length, howlong, adcreation, adtype, addons)
VALUES ('$fullname', '$email', '$companyname', '$companywebsite', '$adspace', '$length', '$howlong', '$adcreation', '$adtype', '$addons')");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con)
?>

    if (!mysql_query($sql,$con))

    where's $sql ? no where, change the line with mysql_query to $sql=YOUR query then the if will actully have something to check

      dagon;10899931 wrote:

      if (!mysql_query($sql,$con))

      where's $sql ? no where, change the line with mysql_query to $sql=YOUR query then the if will actully have something to check

      ok, so I am to replace so it looks like this? (sorry, I am really new to this):

      if ($sql=YOUR query($sql,$con))

      Am I supposed to put submit or something for "YOUR query?" 😕

      I know this all sounds silly, but I dont know what I am supposed to put there?!?

      Thanks for your patience 🙂

        You were closer the first time.
        Try this.

         
        if( mysql_query("INSERT INTO `gmradapply2009` (fullname, email, companyname, companywebsite, adspace, length, howlong, adcreation, adtype, addons)
        VALUES ('$fullname', '$email', '$companyname', '$companywebsite', '$adspace', '$length', '$howlong', '$adcreation', '$adtype', '$addons')") === FALSE ) {
            die('Error: ' . mysql_error());
        }
        echo "1 record added";
        

          i prefer

          $sql="INSERT INTO `gmradapply2009` (fullname, email, companyname, companywebsite, adspace, length, howlong, adcreation, adtype, addons)
          VALUES ('$fullname', '$email', '$companyname', '$companywebsite', '$adspace', '$length', '$howlong', '$adcreation', '$adtype', '$addons')";
          
          if(mysql_query($sql) === FALSE ) {
              die('Error: ' . mysql_error());
          }
          echo "1 record added"; 
          

          but that's just me (easier to debug as you can echo $sql if need be)

            So, should i have built it like this:
            if( mysql_query("INSERT INTO gmradapply2009 (fullname, email, companyname, companywebsite, adspace, length, howlong, adcreation, adtype, addons)
            VALUES ('$fullname', '$email', '$companyname', '$companywebsite', '$adspace', '$length', '$howlong', '$adcreation', '$adtype', '$addons')") === FALSE ) {
            die('Error: ' . mysql_error());
            }
            echo "1 record added";

            Or do I need the repetitive code:
            mysql_query("INSERT INTO gmradapply2009 (fullname, email, companyname, companywebsite, adspace, length, howlong, adcreation, adtype, addons)
            VALUES ('$fullname', '$email', '$companyname', '$companywebsite', '$adspace', '$length', '$howlong', '$adcreation', '$adtype', '$addons')");
            if( mysql_query("INSERT INTO gmradapply2009 (fullname, email, companyname, companywebsite, adspace, length, howlong, adcreation, adtype, addons)
            VALUES ('$fullname', '$email', '$companyname', '$companywebsite', '$adspace', '$length', '$howlong', '$adcreation', '$adtype', '$addons')") === FALSE ) {
            die('Error: ' . mysql_error());
            }
            echo "1 record added";

            Just curious...but either way, the latter worked...THANKS SO MUCH! You have no idea how frustrated I was with this!🙂🙂🙂

              if you do the latter you will insert the data twice, so the former is what you want.

                dagon;10899937 wrote:

                if you do the latter you will insert the data twice, so the former is what you want.

                Got it! thanks again everyone!🙂

                  Is it possible to send the results to an email address as well as the database...or to notify the admin by email that the form has been completed?

                  Perhaps I should post that as a new topic? Sorry...new to the forums too.
                  But you guys rock!

                    Write a Reply...