Hello,

I'm getting an error "Column count doesn't match value count at row 1"

<?
include("db.php");

$ClientsName=$_POST['client'];
$PrgNo=$_POST['prgno'];
$PrgName=$_POST['prgname'];
$TrainerName=$_POST['trainer'];
$Dates=$_POST['dates'];
$Days=$_POST['days'];
$ProfFee=$_POST['fee'];
$TrainerFee=$_POST['trainerfee'];
$ReimbExp=$_POST['rexp'];
$HandoutChg=$_POST['handchg'];
$InvoiceNo=$_POST['invno'];
$TotalInvAmt=$_POST['invamt'];
$FeeRecd=$_POST['feerec'];

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die("Unable to connect to db");

$query = "INSERT INTO tcg VALUES('$ClientsName','$PrgNo','$PrgName','$TrainerName','$Dates','$Days','$ProfFee','$TrainerFee','$ReimbExp','$HandoutChg','$InvoiceNo','$TotalInvAmt','$FeeRecd')";

mysql_query($query) or die(mysql_error());

mysql_close();

echo "Data inserted successfully.";
?>
&nbsp;&nbsp;&nbsp;<a href="insert.html">Insert More</a>

This is the code I'm using.

Database name is vimal_tcg and the table name is also tcg, is this a problem?

First I tried using eg : $client=$_POST and so on. it gave the same error. I thought it might be a problem because the columns are named differently and I changed $client=$_POST to $ClientsName=$_POST and so on.

Even after changing the variables to the ones according to the table in database it gives the same error.

And the fields in the insert.html , insert.php (above code) and the table are 13.

There is one more column in table SlNo which is put to primary unique and auto increment . And ClientsName column is set to INDEX.


Please help.

No, the problem is that you aren't specifying the fields you want to insert into (this should be done even if you are doing them in order to save an internal lookup)

INSERT INTO <table> (field1, field2) VALUES ('field1_value', 'field2_value')

Hi Shawn,

Can you please replace with my variables and put the code back. I don't know php much. I was trying it from a tutorial.

Thank you.

How're you going to learn if you have everyone do it for you?

Ok. Is that like this :

$query = "INSERT INTO tcg ClientsName, PrgNo, PrgName VALUES('$ClientsName','$PrgNo','$PrgName')";

??

Ok. Is that like this :

$query = "INSERT INTO tcg ClientsName, PrgNo, PrgName VALUES('$ClientsName','$PrgNo','$PrgName')";

??

Did you not read my post on how to do it? Go ahead, its about 4 inches above this post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.