Mythiel Posted July 30, 2010 Share Posted July 30, 2010 Been looking around for a solution but so far found nothing. I am trying to update a contact form for my work with PhpMyAdmin. I have done a simple form like this a long while back so i am a bit rusty on understanding what im doing. While waiting for my work server to be updated i have been trying to get someting working on my personal site. I have gotten my old form test to work (data showing up in PhpMyAdmin) but working on the new one hasn't been as easy. The error shown after i submit the form is "Column count doesn't match value count at row 1" Here is my code and attached is my table layout in PhpMyAdmin. <?php if( isset( $_POST['first'] ) ) { $errors = 0; if( $_POST['first'] == '' ) { $first_error = 'Please enter your first name!'; $errors++; } elseif( strlen( $_POST['first'] ) < 2 ) { $first_error = 'Please enter a valid first name!'; $errors++; } elseif( !eregi( '^[a-zA-Z]+((\s|\-)[a-zA-Z]+)?$', $_POST['first'] ) ) { $first_error = 'Please enter a valid first name!'; $errors++; } if( $_POST['last'] == '' ) { $last_error = 'Please enter your last name!'; $errors++; } elseif( strlen( $_POST['last'] ) < 2 ) { $last_error = 'Please enter a valid last name!'; $errors++; } elseif( !eregi( '^[a-zA-Z]+((\s|\-)[a-zA-Z]+)?$', $_POST['last'] ) ) { $last_error = 'Please enter a valid last name!'; $errors++; } if( $_POST['province'] == 'Not Selected' ) { $province_error = 'Please enter your province!'; $errors++; } if( $_POST['country'] == 'Not Selected' ) { $country_error = 'Please enter your country!'; $errors++; } if( $_POST['phone'] == '' ) { $phone_error = 'Please enter a phone number!'; $errors++; } if( $_POST['email'] == '' ) { $email_error = 'Please enter your Email!'; $errors++; } elseif( !eregi( '^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$', $_POST['email'] ) ) { $email_error = 'Please enter a valid Email!'; $errors++; } if( $_POST['info'] == '' ) { $info_error = 'Please let us know what you would like!'; $errors++; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PhP Contact Form</title> </head> <body> <?php if( isset( $_POST['first']) and $errors == 0) { echo '<p>Thank you for your submission!</p>'; $to = 'graphics@softsigns.ca'; $subject = 'Contact Form Submission'; $message = 'You have received a contact form submmision: First Name: '.$_POST['first'].' '; $headers = 'From: Contact Form Alert <FormAlert@softsigns.com>'."\n\r"; mail( $to, $subject, $message, $headers ); $connect = mysql_connect( '*************','*********', '**********' ) or die( mysql_error() ); mysql_select_db( '************', $connect ) or die( mysql_error() ); $query = 'INSERT INTO contactss ( contactss_first, contactss_last, contactss_company, contactss_adress, contactss_city, contactss_provice, contactss_country, contactss_postal, contactss_phone, contactss_fax, contactss_email, contactss_cme, contactss_info ) VALUES ( "'.$_POST['first'].'", "'.$_POST['last'].'", "'.$_POST['company'].'", "'.$_POST['adress'].'", "'.$_POST['city'].'", "'.$_POST['province'].'", "'.$_POST['country'].'", "'.$_POST['postal'].'", "'.$_POST['phone'].'", "'.$_POST['fax'].'", "'.$_POST['email'].'", "'.$_POST['cme'].'", "'.$_POST['info'].'", NOW() )'; mysql_query( $query, $connect ) or die( mysql_error() ); } else { ?> <form id="contact_form" name="contact_form" method="post" action="PhpForm2.php"> <table width="636" border="0"> <tr> <td width="111"> <div align="right">*First Name:</div> </td> <td width="510"> <input type="text" name="first" value="<?php echo @$_POST['first']; ?>"/> <?php echo $first_error; ?> </td> <td width="1" rowspan="11"> </td> </tr> <tr> <td width="111"> <div align="right">*Last Name:</div> </td> <td width="510"> <input type="text" name="last" value="<?php echo @$_POST['last']; ?>"/> <?php echo $last_error; ?> </td> <td width="1" rowspan="11"> </td> </tr> <tr> <td> <div align="right">Company Name:</div> </td> <td> <input type="text" name="company" value="<?php echo @$_POST['company']; ?>"/> </td> </tr> <tr> <td> <div align="right">Adress:</div> </td> <td> <input type="text" name="adress" value="<?php echo @$_POST['adress']; ?>"/> </td> </tr> <tr> <td> <div align="right">City:</div> </td> <td> <input type="text" name="city" value="<?php echo @$_POST['city']; ?>"/> </td> </tr> <tr> <td> <div align="right">*Province:</div> </td> <td> <select name="province"> <option value="Not Selected">- Select Province -</option> <option value="Not Selected"></option> <option value="British Columbia">British Columbia</option> <option value="Alberta">Alberta</option> <option value="Saskatchewan">Saskatchewan</option> <option value="Manitoba">Manitoba</option> <option value="Ontario">Ontario</option> <option value="Quebec">Quebec</option> <option value="New Brunswick">New Brunswick</option> <option value="Prince Edward Island">Prince Edward Island</option> <option value="Nova Scotia">Nova Scotia</option> <option value="Newfoundland and Labrador">Newfoundland and Labrador</option> <option value="Not Selected"></option> <option value="Not Selected">------------</option> <option value="Not Selected"></option> <option value="Yukon">Yukon</option> <option value="Northwest Territories">Northwest Territories</option> <option value="Nunavut">Nunavut</option> </select> <?php echo $province_error; ?> </td> </tr> <tr> <td> <div align="right">*Country:</div> </td> <td> <select name="country" id="country"> <option value="Not Selected">- Country -</option> <option value="Not Selected"></option> <option value="Canada">Canada</option> </select> <?php echo $country_error; ?> </td> </tr> <tr> <td> <div align="right">Postal Code:</div> </td> <td> <input type="text" name="postal" value="<?php echo @$_POST['postal']; ?>"/> </td> </tr> <tr> <td> <div align="right">*Phone Number:</div> </td> <td> <input type="text" name="phone" value="<?php echo @$_POST['phone']; ?>"/> <?php echo $phone_error; ?> </td> </tr> <tr> <td> <div align="right">Fax Number:</div> </td> <td> <input type="text" name="fax" value="<?php echo @$_POST['fax']; ?>"/> </td> </tr> <tr> <td> <div align="right">*Email Adress:</div> </td> <td> <input type="text" name="email" value="<?php echo @$_POST['email']; ?>"/> <?php echo $email_error; ?> </td> </tr> <tr> <td> <div align="right">Contact me by:</div> </td> <td> <select name="cme"> <option value="Phone Me">Phone</option> <option value="Email Me">E-Mail</option> </select> </td> </tr> <tr> <td> <div align="right">*Message:</div> </td> <td colspan="2"> <textarea name="info" cols="60" rows="4"/><?php echo @$_POST['info']; ?></textarea> </td> </tr> <tr> <td> <input type="submit" name="submit" value="submit"> </td> <td colspan="2"> <?php echo $info_error; ?> </td> </tr> </table> </form> <?php } ?> </body> </html> I may have missed something blatently obvious but any help is greatly appreciated. Thanks in adavance [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/209388-mysql-error-column-count-doesnt-match-value-count-at-row-1/ Share on other sites More sharing options...
Maq Posted July 30, 2010 Share Posted July 30, 2010 The INSERT has 13 columns and 14 values. Quote Link to comment https://forums.phpfreaks.com/topic/209388-mysql-error-column-count-doesnt-match-value-count-at-row-1/#findComment-1093329 Share on other sites More sharing options...
Mchl Posted July 30, 2010 Share Posted July 30, 2010 There are 13 fields and 14 values in this query. (And it's also vulnerable to SQL injection) $query = 'INSERT INTO contactss ( contactss_first, contactss_last, contactss_company, contactss_adress, contactss_city, contactss_provice, contactss_country, contactss_postal, contactss_phone, contactss_fax, contactss_email, contactss_cme, contactss_info ) VALUES ( "'.$_POST['first'].'", "'.$_POST['last'].'", "'.$_POST['company'].'", "'.$_POST['adress'].'", "'.$_POST['city'].'", "'.$_POST['province'].'", "'.$_POST['country'].'", "'.$_POST['postal'].'", "'.$_POST['phone'].'", "'.$_POST['fax'].'", "'.$_POST['email'].'", "'.$_POST['cme'].'", "'.$_POST['info'].'", NOW() )'; Quote Link to comment https://forums.phpfreaks.com/topic/209388-mysql-error-column-count-doesnt-match-value-count-at-row-1/#findComment-1093330 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.