Jump to content


Photo

sql in php error, please help


  • Please log in to reply
4 replies to this topic

#1 bdg3

bdg3
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 March 2006 - 01:25 AM

I have an error appearing when tryon to submit data through php from mysql, column count doesnt match value count at row 1. I thought it would be spelling but i cant find it.

here is the php code

<?php
require ('config.php');

$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die ('Could not connect to MySQL Database. ' . mysql_error());

mysql_select_db("bdg3");

$sql1 = "INSERT INTO members (surname,forename,title,date_of_birth,haddress_line1,haddress_line2,haddress_line3,haddress_town_city,haddress_county,haddress_pcode,waddress_line1,waddress_line2,
waddress_line3,waddress_town_city,waddress_county,waddress_pcode,day_num,eve_num,mobile_num,fax_num,email,occupation,interest1,interest2,interest3,mem_start_date,loc_joined_at,region,ml_id,
gift_aid_sub,rugby_club_mem,rugby_club_name) " .
"VALUES (' " . $_POST['surname'] . "',' " . $_POST['forename'] . "',' " . $_POST['title'] . "',' " . $_POST['dob_day'] . "',' " . $_POST['dob_month'] . "',' " . $_POST['dob_year'] . "'," .
"'" . $_POST['haddress_line1'] . "',' " . $_POST['haddress_line2'] . "',' " . $_POST['haddress_line3'] . "',' " . $_POST['haddress_town_city'] . "'," .
"'" . $_POST['haddress_county'] . "',' " . $_POST['haddress_pcode'] . "',' " . $_POST['haddress_pcode'] . "',' " . $_POST['waddress_line1'] . "',".
"'" . $_POST['waddress_line2'] . "',' " . $_POST['waddress_line3'] . "',' " . $_POST['waddress_town_city'] . "',' " . $_POST['waddress_county'] . "'," .
"'" . $_POST['waddress_pcode'] . "',' " . $_POST['day_num'] . "',' " . $_POST['eve_num'] . "',' " . $_POST['mobile_num'] . "'," .
"'" . $_POST['fax_num'] . "',' " . $_POST['email'] . "',' " . $_POST['occupation'] . "',' " . $_POST['interest1'] . "'," .
"'" . $_POST['interest2'] . "',' " . $_POST['interest3'] . "',' " . $_POST['mem_start_date'] . "',' " . $_POST['loc_joined_at'] . "'," .
"'" . $_POST['region'] . "',' " . $_POST['ml_id'] . "',' " . $_POST['gift_aid_sub'] . "',' " . $_POST['rugby_club_mem'] . "'," .
"'" . $_POST['rugby_club_name'] . "');";
mysql_query($sql1) or die ('Could not add user. ' . mysql_error());

echo ('Thankyou, you have success fully managed to add a new member.');
?>

and this is the table creation code.

$SQL1 = "CREATE TABLE IF NOT EXISTS members (
member_id int(6) NOT NULL auto_increment,
surname varchar(20) NOT NULL default '',
forename varchar(20) NOT NULL default '',
title enum('Mr','Mrs','Miss','Dr','Ms', 'Other') NOT NULL default 'Mr',
dob_day int(2)NOT NULL default '1',
dob_month int(2)NOT NULL default '1',
dob_year int(4)NOT NULL default '1910',
haddress_line1 varchar(20) NOT NULL,
haddress_line2 varchar(20),
haddress_line3 varchar(20),
haddress_town_city varchar(20) NOT NULL,
haddress_county varchar(20) NOT NULL,
haddress_pcode varchar(8) NOT NULL,
waddress_line1 varchar(20),
waddress_line2 varchar(20),
waddress_line3 varchar(20),
waddress_town_city varchar(20),
waddress_county varchar(20),
waddress_pcode varchar(8),
day_num int(12) NOT NULL,
eve_num int(12),
mobile_num int(12),
fax_num int(12),
email varchar(40) NOT NULL,
occupation enum('None','Director','Manager','Media','Retired','Self Employed','House Wife','Clerical/Administration','Medical/Healthcare','Legal','Operative','Education','Other')NOT NULL default 'None',
interest1 enum('rugby','football','golf','cricket','tennis','gardening','food','wine','arts & crafts','DIY') NOT NULL default 'rugby',
interest2 enum('rugby','football','golf','cricket','tennis','gardening','food','wine','arts & crafts','DIY'),
interest3 enum('rugby','football','golf','cricket','tennis','gardening','food','wine','arts & crafts','DIY'),
mem_start_date date NOT NULL,
loc_joined_at enum('None','Mailing','At an Event','Online Form','Other') NOT NULL,
region enum('Northamptonshire','Cambridge','Other') NOT NULL default 'Northamptonshire',
ml_id enum('1') NOT NULL default '1',
gift_aid_sub enum('yes','no') NOT NULL default 'yes',
rugby_club_mem enum('yes','no') NOT NULL,
rugby_club_name varchar(30),
PRIMARY KEY (member_id)) TYPE=MyISAM";

If you want the form code aswell i can provide that too.

please help. Thankyou

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 March 2006 - 01:54 AM

column count doesnt match value count is pretty specific ... you're trying to add more data than you have fields declared. The values you are trying to enter include haddress_pcode twice. Fix that and you should get it to work.
Legend has it that reading the manual never killed anyone.
My site

#3 bdg3

bdg3
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 March 2006 - 12:18 PM

Ive deleted that and counted up the fields and they all match, 34 not including the autoincrement field and it still doesnt want to work, any more ideas?

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 March 2006 - 12:40 PM

What errors are you getting?

Ken

What errors are you getting?

Ken

#5 bdg3

bdg3
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 March 2006 - 12:47 PM

still getting the column count doesn't match value count @ row 1 after i have deleted the hadress_pcode that was entered twice.

Here is the code of the form below aswell as this is driving me mad.

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR...nsitional.dtd">
<html>
<head>
<title>Wooden Spoon: Northamptonshire - Home Page </title>
<style type="text/css">
<!--
.style2 {font-family: Arial, Helvetica, sans-serif}
body {
background-color: #FFFFFF;
}
a:link { color : #999999 }
.style3 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: x-small;
color: #FFFFFF;
}
.style4 {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
font-weight: bold;
}
.style5 {font-size: x-small}
.style7 {color: #000066}
a:hover {
color: #0033FF;
}
.style33 {font-size: 14px}
.style34 {font-size: 16px}
.style35 {color: #FF0000}
.style37 {color: #000000}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<table width="66%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="113" colspan="2"><a href="../index.php"><img src="images/title1.jpg" width="780" height="98" border="0"></a></td>
</tr>
<tr>
<td width="35%"><img src="images/title2.jpg" width="266" height="63"></td>
<td width="65%">&nbsp;</td>
</tr>
</table>
<table width="781" height="305" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="163" valign="top"><table width="160" border="0" cellspacing="5" cellpadding="0">
<tr>
<td><a href="../index.php"><img src="images/menu/menu1.jpg" width="140" height="20" border="0"></a></td>
</tr>
<tr>
<td><a href="../about_us.php"><img src="images/menu/menu2.jpg" width="140" height="20" border="0"></a></td>
</tr>
<tr>
<td><img src="images/menu/menu3.jpg" width="140" height="20"></td>
</tr>
<tr>
<td><a href="https://raptor.kent....rship.php"><img src="images/menu/menu4.jpg" width="140" height="20" border="0"></a></td>
</tr>
<tr>
<td><img src="images/menu/menu5.jpg" width="140" height="20"></td>
</tr>
<tr>
<td><img src="images/menu/menu6.jpg" width="140" height="20"></td>
</tr>
<tr>
<td><img src="images/menu/menu7.jpg" width="140" height="20"></td>
</tr>
<tr>
<td><img src="images/menu/menu8.jpg" width="140" height="20"></td>
</tr>
<tr>
<td><img src="images/menu/menu9.jpg" width="140" height="20"></td>
</tr>
<tr>
<td><img src="images/menu/menu10.jpg" width="140" height="20"></td>
</tr>
<tr>
<td><img src="images/menu/menu11.jpg" width="140" height="20"></td>
</tr>
</table>

<table width="159" height="145" border="1" align="right" cellpadding="2" cellspacing="0" bordercolor="#FF0033" bgcolor="#DDDDFF" id="login">
<tr>
<td height="16" bgcolor="#FF0033" class="style3">Members Login</td>
</tr>
<tr>
<td height="108" align="right" class="style2"><form name="form1" method="post" action="../admin.php">
<div align="left">
<p><span class="style5">Username:</span><br />
<input type="text" name="textfield">
<br />
<span class="style5">Password:</span><br />
<input type="text" name="textfield">
<br />
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</p>
</div>
</form></td>
</tr>
</table>
<p>&nbsp;</p></td>
<td width ="10">&nbsp;</td>
<td width ="608" height="305" valign="top" bgcolor="#FFFFFF">
<p class="style4 style7">Membership</p>
<p class="style4 style7 style34">Application Form</p>
<table width="100%" border="0" cellpadding="0" cellspacing="5" bordercolor="#FFFFFF">
<form name="form2" method="post" action="mtransact.php">
<tr align="left" valign="top">
<td width="28%"><span class="style35">Title:</span></td>
<td width="25%">
<select name="title">
<option selected>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Ms</option>
<option>Dr</option>
<option>Other</option>
</select>
</td>
<td width="21%" colspan="2" class="style35"><p align="left">Date of Birth:
<select name="dob_day" size="1">
<option selected="selected">01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<span class="style37">/</span>
<select name="dob_month" size="1">
<option selected="selected">01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select>
<span class="style37"> /</span>
<select name="dob_year" size="1">
<option selected="selected">1910</option>
<option>1911</option>
<option>1912</option>
<option>1913</option>
<option>1914</option>
<option>1915</option>
<option>1916</option>
<option>1917</option>
<option>1918</option>
<option>1919</option>
<option>1920</option>
<option>1921</option>
<option>1922</option>
<option>1923</option>
<option>1924</option>
<option>1925</option>
<option>1926</option>
<option>1927</option>
<option>1928</option>
<option>1929</option>
<option>1930</option>
<option>1931</option>
<option>1932</option>
<option>1933</option>
<option>1934</option>
<option>1935</option>
<option>1936</option>
<option>1937</option>
<option>1938</option>
<option>1939</option>
<option>1940</option>
<option>1941</option>
<option>1942</option>
<option>1943</option>
<option>1944</option>
<option>1945</option>
<option>1946</option>
<option>1947</option>
<option>1948</option>
<option>1949</option>
<option>1950</option>
<option>1951</option>
<option>1952</option>
<option>1953</option>
<option>1954</option>
<option>1955</option>
<option>1956</option>
<option>1957</option>
<option>1958</option>
<option>1959</option>
<option>1960</option>
<option>1961</option>
<option>1962</option>
<option>1963</option>
<option>1964</option>
<option>1965</option>
<option>1966</option>
<option>1967</option>
<option>1968</option>
<option>1969</option>
<option>1970</option>
<option>1971</option>
<option>1972</option>
<option>1973</option>
<option>1974</option>
<option>1975</option>
<option>1976</option>
<option>1977</option>
<option>1978</option>
<option>1979</option>
<option>1980</option>
<option>1981</option>
<option>1982</option>
<option>1983</option>
<option>1984</option>
<option>1985</option>
<option>1986</option>
<option>1987</option>
<option>1988</option>
<option>1989</option>
<option>1990</option>
<option>1991</option>
<option>1993</option>
<option>1994</option>
<option>1995</option>
<option>1996</option>
<option>1997</option>
<option>1998</option>
<option>1999</option>
<option>2000</option>
<option>2001</option>
<option>2002</option>
<option>2003</option>
<option>2004</option>
<option>2005</option>
<option>2006</option>
</select>
<span class="style37">(dd/mm/yyyy)</span> </p>
</td>
</tr>
<tr align="left" valign="top">
<td class="style35">Surname:</td>
<td><input name="surname" type="text" value=" "></td>
<td width="21%" class="style35">Forename:</td>
<td width="26%"><input name="forename" type="text" value=" "></td>
</tr>
<tr align="left" valign="top">
<td colspan="4">&nbsp;</td>
</tr>
<tr align="left" valign="top">
<td colspan="2">Home Address </td>
<td colspan="2">Work Address </td>
</tr>
<tr align="left" valign="top">
<td class="style35">Line 1 </td>
<td><input name="haddress_line1" type="text" value=" "></td>
<td>Line 1 </td>
<td><input name="waddress_line1" type="text"></td>
</tr>
<tr align="left" valign="top">
<td>Line 2 </td>
<td><input type="text" name="haddress_line2"></td>
<td>Line 2 </td>
<td><input type="text" name="waddress_line2"></td>
</tr>
<tr align="left" valign="top">
<td>Line 3 </td>
<td><input type="text" name="haddress_line3"></td>
<td>Line 3 </td>
<td><input type="text" name="waddress_line3"></td>
</tr>
<tr align="left" valign="top">
<td class="style35">Town/City</td>
<td><input name="haddress_town_city" type="text" value=" "></td>
<td>Town/City</td>
<td><input type="text" name="waddress_town_city"></td>
</tr>
<tr align="left" valign="top">
<td class="style35">County</td>
<td><input name="haddress_county" type="text" value=" "></td>
<td>County</td>
<td><input type="text" name="waddress_county"></td>
</tr>
<tr align="left" valign="top">
<td class="style35">Post Code </td>
<td><input type="text" name="haddress_pcode"></td>
<td>Post Code </td>
<td><input type="text" name="waddress_pcode"></td>
</tr>
<tr align="left" valign="top">
<td colspan="4">&nbsp;</td>
</tr>
<tr align="left" valign="top">
<td class="style35">Daytime Telephone:</td>
<td><input name="day_num" type="text" value="0"></td>
<td>Evening Telephone:</td>
<td><input type="text" name="eve_num"></td>
</tr>
<tr align="left" valign="top">
<td>Mobile:</td>
<td><input type="text" name="mobile_num"></td>
<td>Fax:</td>
<td><input type="text" name="fax_num"></td>
</tr>
<tr align="left" valign="top">
<td height="22" class="style35">E-mail:</td>
<td><input name="email" type="text" value=" "></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr align="left" valign="top">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr align="left" valign="top">
<td><span class="style35">Occupation</span>:</td>
<td>
<select name="occupation">
<option selected>None</option>
<option>Director</option>
<option>Manager</option>
<option>Media</option>
<option>Retired</option>
<option>Self Employed</option>
<option>Housewife</option>
<option>Clerical/Administration</option>
<option>Medical/Health care</option>
<option>Legal</option>
<option>Operative</option>
<option>Education</option>
<option>Other</option>
</select>
</td>
<td class="style35">Interest 1:</td>
<td>
<select name="interest1">
<option>None</option>
<option selected>Rugby</option>
<option>Golf</option>
<option>Football</option>
<option>Cricket</option>
<option>Tennis</option>
<option>Gardening</option>
<option>Food</option>
<option>Wine</option>
<option>Arts &amp; Crafts</option>
<option>DIY</option>
</select>
</td>
</tr>
<tr align="left" valign="top">
<td><span class="style35">Region</span>:</td>
<td><select name="region" size="1">
<option selected="selected">Northamptonshire</option>
<option>Cambridgeshire</option>
</select></td>
<td class="style35">Interest 2:</td>
<td>
<select name="interest2">
<option>None</option>
<option>Rugby</option>
<option selected="selected">Golf</option>
<option>Football</option>
<option>Cricket</option>
<option>Tennis</option>
<option>Gardening</option>
<option>Food</option>
<option>Wine</option>
<option>Arts &amp; Crafts</option>
<option>DIY</option>
</select>
</td>
</tr>
<tr align="left" valign="top">
<td class="style35">Gift Aid Subcriber:</td>
<td><select name="gift_aid_sub" size="1">
<option selected="selected">Yes</option>
<option>No</option>
</select></td>
<td class="style35">Interest 3:</td>
<td>
<select name="interest3">
<option>None</option>
<option>Rugby</option>
<option>Golf</option>
<option selected="selected">Football</option>
<option>Cricket</option>
<option>Tennis</option>
<option>Gardening</option>
<option>Food</option>
<option>Wine</option>
<option>Arts &amp; Crafts</option>
<option>DIY</option>
</select>
</td>
</tr>
<tr align="left" valign="top">
<td class="style35">Rugby Club Member</td>
<td><select name="rugby_club_mem" size="1">
<option selected="selected">Yes</option>
<option>No</option>
</select></td>
<td>:Rugby Club Name:</td>
<td><input type="text" name="rugby_club_name"></td>
</tr>
<tr>
<td colspan="4">&nbsp;</td>
</tr>


<tr class="style4 style7 style33">
<td colspan="4">For Office Use Only</td>
</tr>
<tr class="style4 style7 style33">
<td colspan="4">&nbsp;</td>
</tr>

<tr>
<td>Mailing List ID</td>
<td><select name="ml_id">
<option selected="selected">1</option>
</select></td>
<td>Location Joined At</td>
<td><select name="loc_joined_at" size="1">
<option selected="selected">Online Form</option>
</select></td>
</tr>
<tr>
<td colspan="2">Membership Starting Date:
<input type="text" name="mem_start_date" /></td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="4"><span class="style4 style7 style33">
<input name="submit" type="submit" value="submit" />
<input name="reset" type="reset" value="reset" />
</span> </td>
</tr></form>
</table>
<p class="style4 style7 style33">&nbsp;</p></td>
</tr></form>
</table>
</body>
</html>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users