0

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>

2
Contributors
1
Reply
7
Views
2 Years
Discussion Span
Last Post by tobyITguy
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.