Good afternoon,

I have a very little knowledge in php mysql. I want to make a periodical report of my company's strength of various departments. I have a html page like
<!DOCTYPE html> <html> <head></head> <body> <form action="" method="post">
Department : <select name="dept"><option>admin</option><option>finance</option><option>motor dept</option><option>logistics</option></select>
Designations:<select name="design"><option>clerks</option><option>executives</option><option>helpers</option><option>drivers</option></select>
No. of employees:<input type="text" name="persons" size=3"/> <input type="submit" name="submit"/></form>

//php code
<?php
$dept=$_POST["dept"];
$design=$_POST["design"];
$persons=$_POST["persons"];

$connect=mysql_connect("localhost", "root", "") or die ("error");
mysql_select_db("db", $connect);
$sql="INSERT INTO strength(dept, clerks, executives, helpers drivers) values ('$dept', '$design')";
?>

MY TABLE VIEW SHOULD COME LIKE:

     CLERKS  EXECUTIVES   HELPERS   DRIVERS

ADMIN

FINANCE

LOGISTICS

MOTOR DE

ERROR IS COMING LIKE: fields and values mismatch(it probably insert command mistake) Please help in this regard.

?> </body> </html>

You are trying to add data into 5 columns but your supplying only 2 columns of data.

$sql="INSERT INTO strength(dept, clerks, executives, helpers drivers) values ('$dept', '$design')";

Between helpers and drivers theres supposed to be a comma.

You collected persons variable and never used it.

To fix the insert error your code should be something like this

<?php
$clerks = $_POST['clerks'];// do this for all the variables in the values section
$dept=$_POST["dept"];

$connect=mysql_connect("localhost", "root", "") or die ("error");
mysql_select_db("db", $connect);
$sql="INSERT INTO strength(dept, clerks, executives, helpers, drivers) values ('$dept', '$clerks','$executives','$helpers','$drivers')";
?>

Then you need to update your html code putting inputs that correspend with all the variables.

If your trying to select data from the database and report it to the user using a html page, then you need to redo everything because your getting it wrong.

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.