INSERT INTO mysql

by 6 replies
7
Getting this error
"Couldn't Add Note Please See AdminYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('April 3, 2012','','Hello I really Hope I get this to work soon','') W' at line 1"

using this code

PHP Code:
if (isset($_POST['submit'])) {
$message $_POST['message'];
$date date("F j, Y");
$id $_GET['id'];
 
$insert mysql_query("INSERT INTO `jeffdesj`.`notes` (date,user,message,,) VALUES ('$date','$user','$message','') WHERE client_id=$id") or die ("Couldn't Add Note Please See Admin" mysql_error());

 if (
$insert) {
 echo 
"<div align='center'><font color='red'>Note Added Successfully Please Refresh</font></div>";
 }

I dunno what I'm missing?? I'm using _GET cause I have appending the id in the link..
#programming #insert #mysql
  • (date,user,message,,) - looks like you miss one column name
  • Ohh... Also... You can't use INSERT with WHERE, you should use UPDATE ...
    • [ 1 ] Thanks
  • AHHHHHHHHHHHHHHHH
  • Try this:

    mysql_query("INSERT INTO your_table_name SET date='$date',user='$user',message='$message' WHERE client_id='$id'") or die ("Couldn't Add Note Please See Admin" . mysql_error());
    • [1] reply
    • Also you should really never just insert stuff into the database from a POST without validating the input first, you are just asking to get hacked...
  • Yes, use the mysql_real_escape_string function to prevent hacking.
  • [DELETED]
  • Banned
    [DELETED]

Next Topics on Trending Feed

  • 7

    Getting this error "Couldn't Add Note Please See AdminYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('April 3, 2012','','Hello I really Hope I get this to work soon','') W' at line 1"