Welcome to WebmasterWorld Guest from 54.205.74.11

Forum Moderators: coopster & jatar k

Error: Column count doesn't match value count at row

php , mysql error

   
8:42 pm on Dec 7, 2007 (gmt 0)

5+ Year Member



<b> i am getting an erroe coloumn count does not match value count at row . I have been through it a thosand times and lost. the mysql table has id in it which i am passing as NULL? </b> <i> is that correct? </i>

<strong>the mysql table has 29 column i am passing 28 plus 1 id?
but it chooses to be difficult.

any help will do .
</strong>

<form name ="input" action="test.php" method="post">
<table border="0">
<tr>
<td>Company:</td><td> <input class="input" type="text" name="Company"/></td></tr><tr>
<td>name:</td><td> <input class="input" type="text" name="name" /></td></tr><tr>
<td>address1:</td><td> <input class="input" type="text" name="add" /></td></tr><tr>
<td>address2:</td><td> <input class="input" type="text" name="addr" /></td></tr><tr>
<td>address3:</td><td> <input class="input" type="text" name="addressc"/></td></tr><tr>
<td>pobox:</td><td> <input class="input" type="text" name="pobox" /></td></tr><tr>
<td>suburb:</td><td> <input class="input" type="text" name="suburb" /></td></tr><tr>
<td>city:</td><td> <input class="input" type="text" name="city" /></td></tr><tr>
<td>area:</td><td> <input class="input" type="text" name="area" /></td></tr><tr>
<td>province:</td><td> <input class="input" type="text" name="province"/></td></tr><tr>
<td>country:</td><td> <input class="input" type="text" name="country" /></td></tr><tr>
<td>tel:</td><td> <input class="input" type="text" name="tel" /></td></tr><tr>
<td>fax:</td><td> <input class="input" type="text" name="fax" /></td></tr><tr>
<td>email:</td><td> <input class="input" type="text" name="email" /></td></tr><tr>
<td>rooms:</td><td> <input class="input" type="text" name="rooms" /></td></tr><tr>
<td>description:</td><td> <textarea rows=15 cols=40 type="text" name="description" /></textarea></td></tr><tr>
<td>Keyword:</td><td> <input class="input" type="text" name="keyword" /></td></tr><tr>
<td>Heading:</td><td> <input class="input" type="text" name="heading" /></td></tr><tr>
</tr><tr>
<td></td><td> Select Type of Hotel:</td><td>
<select name="type">
<option value="Romantic">Romantic</option>
<option value="Boutique">Boutique</option>
<option value="Historic">Historic</option>
<option value="Countryside">Countryside</option>
<option value="Self">Self Catering</option>
<option value="Family">Family Friendly</option>
<option value="Spa">Spa</option>
</select>:<br/></td></tr><tr>
<td></td><td> Select Type of Hotel:</td><td>
<select name="typeb">
<option value="none"> </option>
<option value="Romantic">Romantic</option>
<option value="Boutique">Boutique</option>
<option value="Historic">Historic</option>
<option value="Countryside">Countryside</option>
<option value="Self">Self Catering</option>
<option value="Family">Family Friendly</option>
<option value="Spa">Spa</option>
</select>:<br/></td></tr><tr>
<td></td><td>Hotel Quality:</td><td>
<select name="Quality">
<option value="Economy">Economy</option>
<option value="Midrange">Midrange</option>
<option value="Luxury">Luxury</option></td></tr><tr>
<td></td><td>Meeting </td><td> <input type="checkbox" name="Meeting" value="Meeting Facilities" /></td></tr><tr>
<td></td><td>Gym </td><td><input type="checkbox" name="Gym" value="Gym" /></td></tr><tr>
<td></td><td>Pet Friendly </td><td><input type="checkbox" name="Pet" value="Pet Friendly" /></td></tr><tr>
<td></td><td>Internet</td><td><input type="checkbox" name="Internet" value="Internet" /></td></tr><tr>
<td></td><td>Pool</td><td> <input type="checkbox" name="Pool" value="Pool" /></td></tr><tr>
<td></td><td>Restaurant</td><td><input type="checkbox" name="Restaurant" value="restaurant" /></td></tr><tr>
<td></td><td>Breakfast</td><td><input type="checkbox" name="Breakfast" value="Breakfast included" /></td></
</tr><tr>
</table>
<input type="submit" value="submit">

php code :

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$company=$_POST[company] ;
$name=$_POST[name];
$add=$_POST[add];
$addr=$_POST[addr];
$addressc=$_POST[addressc];
$pobox=$_POST[pobox];
$suburb=$_POST[suburb];
$city=$_POST[city];
$area=$_POST[area];
$province=$_POST[province];
$country=$_POST[country];
$tel=$_POST[tel];
$fax=$_POST[fax];
$email=$_POST[email];
$rooms=$_POST[rooms];
$description=$_POST[description];
$keyword=$_POST[keyword];
$heading=$_POST[heading];
$type=$_POST[type];
$typeb=$_POST[typeb];
$quality=$_POST[quality];
$meeting=$_POST[meeting];
$gym=$_POST[gym];
$pet=$_POST[pet];
$internet=$_POST[internet];
$pool=$_POST[pool];
$restaurant=$_POST[restaurant];
$breakfast=$_POST[breakfast];

mysql_select_db("my_db", $con);

$sql="INSERT INTO hotel
(

Id,Company,name,addressa,addressb,addressc,pobox,suburb,city,area,province,country,tel,fax,email,rooms,descriptio

n,keyword,heading,type,typeb,quality,meeting,gym,pet,internet,pool,restaurant,breakfast)
VALUES
(

NULL,'$company','$name','$add','$addr','$addressc','$pobox','$suburb','$city','$area','$province','$country','$te

l','$fax','$email','$rooms','$description''$keyword','$heading','$type','$typeb','$quality','$meeting','$gym','$p

et','$internet','$pool','$restaurant','$breakfast')";

Echo "connect ok done";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

11:23 pm on Dec 7, 2007 (gmt 0)

5+ Year Member



Is your ID column set to auto_increment in mySQL? If so, I would take the field and value out of the query.

'Column count does not match' usually means the number of fields and the number of values are different.

11:26 pm on Dec 7, 2007 (gmt 0)

5+ Year Member



You're missing a comma here: '$description''$keyword' and since the '' construct is a valid way of escaping single-quotes in SQL, this becomes a single string with a ' in the middle.

Also make sure you're escaping single-quotes etc when building your SQL statement. Apostrophes are common in names and company names and will cause errors if not escaped.

Hope this helps.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month