jennymuz Posted February 18, 2018 Share Posted February 18, 2018 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 connectionif ($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 Quote Link to comment Share on other sites More sharing options...
benanamen Posted February 18, 2018 Share Posted February 18, 2018 You cant see you are trying to insert five values using 4 columns? $query = "INSERT INTO expmarke_main.contactform (name, email, phone, message) VALUES('$name','$email', '$phone', '$message', '$emailmarketing')"; Quote Link to comment Share on other sites More sharing options...
Barand Posted February 18, 2018 Share Posted February 18, 2018 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.