473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Column count doesn't match value count at row 1

hi

i am trying to insert a record via a form using php and mysql and when i try to submit the form it comes up with the following error

Column count doesn't match value count at row 1

if someone can please help me overcome this error i would be grateful.

the insert_shirt.php code is:

[PHP]<?php
$conn = mysql_connect("localhost","root","")
or die (mysql_error());
mysql_select_db("noble",$conn);

$insert = "INSERT INTO Shirts
VALUES('$_POST[Shirt_ID]','$_POST[Smart_ID]','$_POST[Shirt_Brand]','$_POST[Shirt_Type]',
'$_POST[Shirt_Colour]','$_POST[Shirt_Price]','$_POST[Shirt_image]',
'$_POST[Shirt_Description]')";

if (mysql_query($insert,$conn)) {
echo "Record Added";
} else {
echo mysql_error();
}
?>[/PHP]

the form code is :

[HTML]<body>
<h1><img src="Web Images/Banners/SuitFormTitle1.jpg"></img></h1>
<table>
<tr>
<td>
<h3>
<a href="Suit_Form.html"><img src="Web Images/Buttons/Smart.jpg"></img></a><br />
<a href="Casual_Form.html"><img src="Web Images/Buttons/Casual.jpg"></img></a><br />
<a href="Suit_Form.html"><img src="Web Images/Buttons/Urban.jpg"></img></a><br />
</h3>
</td>
</tr>
</table>
<div style='margin:0 auto;width:600px;'>
<form action="Insert_Shirt.php" method="post">
<div class="row">
<span class="item"><h2>Shirt ID</h2></span>
<span class="formw"><input type="text" name="Shirt_ID" size="5" /></span>
</div>
<div class="row">
<span class="item"><h2>Smart ID</h2></span>
<span class="formw"><input type="text" name="Smart_ID" value="2" size="5" /></span>
</div>
<div class="row">
<span class="item"><h2>Shirt Brand</h2></span>
<span class="formw"><input type="text" name="Shirt_Brand" size="20"/></span>
</div>
<div class="row">
<span class="item"><h2>Shirt Type</h2></span>
<span class="formw"><input type="text" name="Shirt_Type" size="20"/></span>
</div>
<div class="row">
<span class="item"><h2>Shirt Colour</h2></span>
<span class="formw"><input type="text" name="Shirt_Colour" size="20"/></span>
</div>
<div class="row">
<span class="item"><h2>Shirt Price</h2></span>
<span class="formw"><input type="text" name="Shirt_Price" size="10"/></span>
</div>
<div class="row">
<span class="item"><h2>Shirt Image</h2></span>
<span class="formw"><input type="text" name="Shirt_image" size="30" value="web images\Items\Shirts\" /></span>
</div>
<div class="row">
<span class="item"><h2>Shirt Description</h2></span>
<span class="formw"><textarea name="Shirt_Description" rows="5" cols="20"></textarea></span>
</div>
<div class="row">
<span class="item"></span>
<span class="formw"><input type="image" name="submit" src="Web Images/Buttons/Submit.jpg"/></span>
</form>
</div>
</body>[/HTML]

i am trying to insert the following values:

Expand|Select|Wrap|Line Numbers
  1. '1',
  2. '2',
  3. 'YSL',
  4. 'Pleated',
  5. 'Grey',
  6. '90.00',
  7. 'image_url',
  8. 'Description'.
thanks in advance

ashraf
Mar 25 '08 #1
6 1815
ronverdonk
4,258 Expert 4TB
I can't see it from the code, but maybe I am shortsghted. One problem could be that you have more columns than you insert (what about an index column?).

Best way to do such an insert is to name the columns in your sql statement. Since you have not done that, the quickest way now is to do an [php]echo $insert;[/php]right before the mysql_query and you can see the contents and check the hnumber of columns in the sql statement.

Ronald
Mar 25 '08 #2
Markus
6,050 Expert 4TB
I can't see it from the code, but maybe I am shortsghted. One problem could be that you have more columns than you insert (what about an index column?).

Best way to do such an insert is to name the columns in your sql statement. Since you have not done that, the quickest way now is to do an [php]echo $insert;[/php]right before the mysql_query and you can see the contents and check the hnumber of columns in the sql statement.

Ronald
Well, he hasn't given php the names of the columns he wants to INSERT INTO, so ofcourse php will throw an error, right?
Mar 25 '08 #3
ronverdonk
4,258 Expert 4TB
Well, he hasn't given php the names of the columns he wants to INSERT INTO, so of course php will throw an error, right?
No you don't have to give the column names, you can do it with VALUE() only.

But then you must be sure that you specify the values for ALL columns in the table. Usually you forget the primary key auto_increment field, because you think that it will be done by default, but that is not true. For such a column you must specify a zero (0), then it will be auto incremented when inserted. But you may not omit any column values when using just VALUES().

Ronald
Mar 25 '08 #4
Markus
6,050 Expert 4TB
No you don't have to give the column names, you can do it with VALUE() only.

But then you must be sure that you specify the values for ALL columns in the table. Usually you forget the primary key auto_increment field, because you think that it will be done by default, but that is not true. For such a column you must specify a zero (0), then it will be auto incremented when inserted. But you may not omit any column values when using just VALUES().

Ronald
I see.

Could you use NULL for the auto-increment aswell?
Mar 25 '08 #5
ronverdonk
4,258 Expert 4TB
I see.

Could you use NULL for the auto-increment as well?
In the insert you mean? Yes, the row will normally auto increment with that (as if it were a 0).

Ronald
Mar 25 '08 #6
thanks guys i have figured out the problem i took the advice of ronald and looked at my sql table i had a colour field in the code and not on the table. kinda stupid from my part.

thanks alot

ashraf.
Mar 25 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Aaron C | last post by:
Hi, I'm trying to do an insert with the following statement: INSERT INTO user VALUES ( 'ag@ag.com','ag','Aaron','Chandler','','','La Mirada','CA',90638,714,'',''); and I'm getting the error...
6
by: M.Kamermans | last post by:
I have an XSLT script that has to operate on some particularly nasty XML to turn it into a SQL databse, but 'entries' in the XML aren't actually unique, so their unique identifier is useless. I...
1
by: Dmitry V. Markin | last post by:
Good day! Here is my problem: I need to have a radiobutton column in my DataGrid for a representation of a bool column, where only row can be checked at one time(only one value in bool column...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
23
by: Gary Wessle | last post by:
Hi I have a vector<charwhich looks like this (a d d d a d s g e d d d d d k) I need to get the biggest count of consecutive 'd'. 5 in this example I am toying with this method but not sure if...
5
by: John | last post by:
I just cannot manage to perform a SELECT query with NULL parameter... My CATEGORY table does have one row where TCATEGORYPARENTID is null (real DB null value). TCATEGORYID and TCATEGORYPARENTID...
6
by: Jay | last post by:
I need to convert from a string a double that is followed by a scaling character (k means *1e3, M=*1e6, etc) then apply the scaling character. Example: "-1.345k #comment" I know roughly how...
0
by: Joe Meng | last post by:
Greetings, I've seen this question asked and answered here, just not completely yet. I'm wondering how to use a column value as a table name in another query. So far it's looking like you must...
1
by: Byomokesh | last post by:
Hi I am trying to cell count and match in tgroup cols value in XML file. if cell count and tgrou cols value is mismatch, its showing error. My xml -------------- <tgroup cols="3"> <colspec...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.