i' saved the key names as column names in database.so i want to insert i all the values in database.with out mentioning the column names in the database.
<html>
<body>
<form action="#" method="post">
Firstname: <input type="text" name="name">
Lastname: <input type="text" name="lname">
Age: <input type="text" name="age">
<input type="submit">
</form>
</body>
</html>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$con = mysql_connect("localhost","root","enter");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$insData=($_POST);
$columns = implode(",",array_keys($insData));
echo $columns;
$escaped_values = array_map('mysql_real_escape_string', array_values($insData));
$values = implode(",", $escaped_values);
echo $values;
$sql = "INSERT INTO name ($columns) VALUES ('$values')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
}
?>
wen code executes it's displaying error like this:name,lname,ageESWARA,Manikanta Varma,22Error: Column count doesn't match value count at row 1...
i'm having table name with 3columns like name,lname.age. ..can u please correct my code