homepage Welcome to WebmasterWorld Guest from 174.129.76.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Error: Column count doesn't match value count at row
php , mysql error
malcolmcroucher

5+ Year Member



 
Msg#: 3522720 posted 8:42 pm on Dec 7, 2007 (gmt 0)

<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";

 

themistral

5+ Year Member



 
Msg#: 3522720 posted 11:23 pm on Dec 7, 2007 (gmt 0)

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.

borntobeweb

5+ Year Member



 
Msg#: 3522720 posted 11:26 pm on Dec 7, 2007 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved