0

i am trying to connect a form to mysql database by using php code,but once a click submit button to submit the form this is the error am getting.

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by) VALUES ('','','')' at line 1


please help to troubleshoot this.

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by gikonyo
0

<?php
session_start();
$con = mysql_connect("localhost","root","");
if (!$con)
{
die ('could not connect: '.mysql_error());
}

mysql_select_db("scanad_kenya", $con);

$topic= $_POST;
$bodyn= $_POST;
$by= $_POST;


$sql="INSERT INTO news_feed(topic,bodyn,by) VALUES ('$topic','$bodyn','$by')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "your comment sucessfully added";
header("location:homenews.php");
mysql_close($con)
?>

the above is the code that is connecting to the database

0

Try this

<?php
session_start();
$con = mysql_connect("localhost","root","");
if (!$con)
{
die ('could not connect: '.mysql_error());
}

mysql_select_db("scanad_kenya", $con);

$topic= $_POST['topic'];
$bodyn= $_POST['bodyn'];
$by= $_POST['by'];


$sql="INSERT INTO news_feed VALUES ('$topic','$bodyn','$by')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "your comment sucessfully added";
header("location:homenews.php");
mysql_close($con)
?>
0

thanks alot well the previous error is gone but the following error results.

Error: Column count doesn't match value count at row 1

0

thanks alot for your concern the error was in the naming of columns.

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.