Jump to content

mysqli insert error


jennymuz

Recommended Posts

I am trying to get my website contact form to submit into database. I have tried a few things but it seems to be getting worse.

 

This is my error

Please enquire hereERROR: Could not able to execute INSERT INTO expmarke_main.contactform (name, email, phone, message) VALUES('','', '', '', ''). Column count doesn't match value count at row 1

 

this is my code. It is linking to database.

 

?php
$servername = "10.169.0.164";
$username = "expmarke_main";
$password = "misty44";
$dbname = "expmarke_main";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Please enquire here";
   
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$phone = mysqli_real_escape_string($conn, $_POST['phone']);
$message = mysqli_real_escape_string($conn, $_POST['message']);
$emailmarketing = mysqli_real_escape_string($conn, $_POST['emailmarketing']);

$query = "INSERT INTO expmarke_main.contactform (name, email, phone, message) VALUES('$name','$email', '$phone', '$message', '$emailmarketing')";

if(mysqli_query($conn, $query)){
    echo "Records inserted successfully.";
} else{
    echo "ERROR: Could not able to execute $query. " . mysqli_error($conn);
}
?>

 

this is my contact form

 


<html>
<section id ="contact">
      <div class="container">
        <div class="row">
          <div class="col-lg-12 text-center">
            <h2 class="section-heading">Contact Us</h2>
            <p>Please contact us for an informal chat to discuss your needs.</p>
          </div>
        </div>
        <div class="row">
          <div class="col-lg-12">
            <form id="contactForm" name="sentMessage" novalidate>
            <form action="post" method="db.php">
              <div class="row">
                <div class="col-md-6">
                  <div class="form-group">
                 <input class="form-control" name="name" value="name" id="name" type="text" placeholder="Your Name *" required data-validation-required-message="Please enter your name.">
                    <p class="help-block text-danger"></p>
                  </div>
                  <div class="form-group">
                    <input class="form-control" name="email" value="email" id="email" type="email" placeholder="Your Email *" required data-validation-required-message="Please enter your email address.">
                    <p class="help-block text-danger"></p>
                  </div>
                  <div class="form-group">
                    <input class="form-control" name="phone" id="phone" value="phone" type="tel" placeholder="Your Phone *" required data-validation-required-message="Please enter your phone number.">
                    <p class="help-block text-danger"></p>
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="form-group">
                    <textarea class="form-control" "rows=7" name="message" value="message" id="message" placeholder="Your Message *" required data-validation-required-message="Please enter a message."></textarea>
                    <p class="help-block text-danger"></p>
                  </div>
                </div>
                  <div class="form-group">       
           <div class="col-lg-12">
        <div class="checkbox">
            <input type="hidden" name="emailmarketing" id="emailmarketing" value="0">
          <label><input type="checkbox" name="emailmarketing" id="emailmarketing" value="1">Tick to receive emails to help your business grow </label>
        </div>
      </div>
    </div>
                 
                <div class="clearfix"></div>
                <div class="col-lg-12 text-center">
                  <div id="success"></div>
                  <button id="sendMessageButton" onclick="myFunction()  class="btn btn-xl" input type="submit" value="Submit" >Send Message</button>
                </div>
              </div>
            </form>
              </form>
          </div>
        </div>
      </div>
    </section>
   
    </html>

please help

Link to comment
Share on other sites

 

Column count doesn't match value count at row 1

Which do have trouble with, reading or counting?

 

INSERT INTO expmarke_main.contactform (name, email, phone, message) VALUES('$name','$email', '$phone', '$message', '$emailmarketing')
                                         |     |      |       |               |        |         |          |              |
                                         +--------------------+               +--------------------------------------------+
                                               4 columns                                      5 values
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.