0

please help me
it usually gives me error ( it says cant enter the values )

<?php
$host = "localhost";
$con = mysql_connect("localhost","awah","password") or die ("error to connect to the server");

// contact the table and enter the form
mysql_select_db("kigalifinders_clanteam_admin", $con);
$query = mysql_query("INSERT INTO contacts(from, subject, message) value('$_POST[email]','$_POST[subject]','$_POST[messgae]')");
if(!$query)
{
die ("cant enter the values");
}
mysql_close();
?>
5
Contributors
13
Replies
14
Views
6 Years
Discussion Span
Last Post by sudeepjd
0

It should be:

INSERT INTO table (columns) VALUES (values)

instead of VALUE.

Edited by pritaeas: n/a

0

Hi, dear

Check this out!

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

mysql_select_db("my_db", $con);

$sql="INSERT INTO contacts (from, subject, message)
VALUES
('$_POST[email]','$_POST[subject]','$_POST[message]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?>
0

i have got this error

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 'from, subject, message) VALUES ('awah.mohamad@yahoo.com','what is wrong in this ' at line 1
0

Have u checked this script on any server... because same error. i think there is some bug in php version...

0

The problem is that "from" is a sql keyword. If you use a keyword as a column name, you need to encapsulate it. If you don't, sql will think you are asking for a query FROM a database.

Here is the correct syntax. INSERT INTO contacts (`from`, `subject`, `message`) VALUES ('{$_POST['email']}','{$_POST['subject']}','{$_POST['message']}')"; And it is good coding practice to encapsulate the other variables as well as I have show above.

All the best.

Edited by sudeepjd: n/a

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.