Jump to content

[SOLVED] Inserting information into MYSQL Database


Scott87

Recommended Posts

Not sure whether this is the right section to post this into (I couldn't see a MYSQL help section).

 

I have a form:

 

<form method="post" action="confirm.php">

                <fieldset>

                        <p><em>Your Name</em><br /><input type="text" name="txtName" class="input" /></p>

                        <p><em>Studio / Business Name</em><br /><input type="text" name="txtCompanyName" class="input" /></p>

                        <p><em>Length of time in business</em><br /><select name="selTimeBusiness" size="1" class="dropdown">

                            <option value="">Please Select … </option>

                            <option value="1">1 Year</option>

                            <option value="2">2 Years</option>

                            <option value="3">3 Years</option>

                            <option value="4">4 Years</option>

                            <option value="5">5 Years</option>

                            <option value="+6">+6 Years</option>

                        </select></p>

                        <p><em>Is this your fulltime employment?</em><br /><select name="selTimeEmployment"  class="dropdown">

                          <option value="">Please Select … </option>

                          <option value="1">Yes</option>

                          <option value="2">No</option>                           

                        </select></p>

                        <p><em>Address</em><br /><textarea  rows="4" cols="30" name="txtAddress" class="input"></textarea></p>

                        <p><em>Phone</em><br /><input type="text" name="txtPhone" class="input" /></p>

                        <p><em>Email</em><br /><input type="text" name="txtEmail" class="input" /></p>

                        <p><em>Website</em><br /><input type="text" name="txtWebsite" class="input" /></p>

                        <p><em>How did you hear about us?</em><br />

                        <select name="selHeardAboutUs" size="1" class="dropdown">

                            <option value="UNANSWERED">Please select...</option>

                            <option value="Google Search">Google Search</option>

                            <option value="SWPP Magazine">SWPP Magazine</option>

                            <option value="BIPP Photographer Magazine">BIPP Photographer Magazine</option>

                            <option value="Word of Mouth">Word of Mouth</option>

                            <option value="Other">Other</option>

                        </select></p>

                        <p><em>If you selected Other please state where below:</em><br /><input type="text" name="txtOther" class="input" /></p>

                        <p><em>Message</em><br /><textarea rows="8" cols="50" name="msg" class="input"></textarea></p>

                        <p><em>Request a Brochure </em> <input class="input" type="checkbox" name="checkBrochure" /></p>

                        <p><em>Sign up to our Newsletter </em> <input class="input" type="checkbox" name="checkSignup" /></p>

                    </fieldset><br />

                    <p><input type="submit" class="submit" value="Submit" name="submit" /></p>

</form>

 

 

Once completed and submitted it processes confirm.php which has an include of brochurerequest.php - this is where my code for the form is.

 

<?php

 

 

if($_POST){

 

$txtName = isset($_POST['txtName']) ? $_POST['txtName'] : NULL;

$txtCompanyName = isset($_POST['txtCompanyName']) ? $_POST['txtCompanyName'] : NULL;

$selTimeBusiness = isset($_POST['selTimeBusiness']) ? $_POST['selTimeBusiness'] : NULL;

$selTimeEmployment = isset($_POST['selTimeEmployment']) ? $_POST['selTimeEmployment'] : NULL;

$txtAddress = isset($_POST['txtAddress']) ? $_POST['txtAddress'] : NULL;

$txtPhone = isset($_POST['txtPhone']) ? $_POST['txtPhone'] : NULL;

$txtEmail = isset($_POST['txtEmail']) ? $_POST['txtEmail'] : NULL;

$txtWebsite = isset($_POST['txtWebsite']) ? $_POST['txtWebsite'] : NULL;

$selHeardAboutUs = isset($_POST['selHeardAboutUs']) ? $_POST['selHeardAboutUs'] : NULL;

$txtOther = isset($_POST['txtOther']) ? $_POST['txtOther'] : NULL;

$msg = isset($_POST['msg']) ? $_POST['msg'] : NULL;

$checkBrochure = isset($_POST['checkBrochure']) ? $_POST['checkBrochure'] : NULL;

$checkSignup = isset($_POST['checkSignup']) ? $_POST['checkSignup'] : NULL;

 

}

 

// Send to database

 

mysql_query("INSERT INTO contact_form (txtName, txtCompanyName, selTimeBusiness, selTimeBusiness, txtAddress, txtPhone, txtEmail, txtWebsite, selHeardAboutUs, txtOther, msg, checkBrochure, checkSignup)

    VALUES ('$txtName', '$txtCompanyName', '$selTimeBusiness', '$txtAddress', '$txtPhone', '$txtEmail', '$txtWebsite', '$selHeardAboutUs', '$txtOther','$msg', '$checkBrochure', '$checkSignup')");

 

?>

 

I've set (at least I think I have) the database table/fields up correctly. But the information doesn't go into the database as it should.

 

Any ideas - i'm quite new to mysql/php so forgive me if its a mess ! :D

 

 

Thanks

Scott

For debuging purposes use this...

 

$sql = "INSERT INTO contact_form (txtName, txtCompanyName, selTimeBusiness, selTimeBusiness, txtAddress, txtPhone, txtEmail, txtWebsite, selHeardAboutUs, txtOther, msg, checkBrochure, checkSignup)
              VALUES ('$txtName', '$txtCompanyName', '$selTimeBusiness', '$txtAddress', '$txtPhone', '$txtEmail', '$txtWebsite', '$selHeardAboutUs', '$txtOther','$msg', '$checkBrochure', '$checkSignup')";
mysql_query($sql) or die(mysql_error() . "<br />$sql");

are any of your db fields INTs?  because you have all those variables quoted and that's usually what will break a query.  if that doesn't fix it (it doesn't look like it should) then try what thorpe posted.  that should set you on the right path.

Hey, thanks for that - I should use debugging to my advantage!

 

This is the message I get when using the debugging code you gave me:

 

Column count doesn't match value count at row 1

INSERT INTO contact_form (txtName, txtCompanyName, selTimeBusiness, selTimeBusiness, txtAddress, txtPhone, txtEmail, txtWebsite, selHeardAboutUs, txtOther, msg, checkBrochure, checkSignup) VALUES ('', '', '', '', '', '', '', '', '','', '', '')

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.