Jump to content

Please help (Really frusterating SQL error on something due tomorrow)


RTS

Recommended Posts

I have a project due tomorrow, and have been up til late working on this. can anyone tell me what is wrong with this code? This is the error I get

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,message,date) VALUES ('p13','p13','jahjsbubf','May 15, 2007, 11:59 PM')' at line 1

 

for the code

<?php
session_start();
$text = $_POST['message'];
$user = $_SESSION['username'];
$user2 = $_GET['user'];
$date = date('F j, Y, h:i A');
$con = mysql_connect("localhost","ZackBabtkis","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

mysql_query("INSERT INTO comments (username,from,message,date) 
VALUES ('$user2','$user','$text','$date')") or die('Error: ' . mysql_error());
mysql_close($con);
header("location: /users/$user2");
?>

Try using these ``.

Sometimes it helps.

 

Like this:

<?php
session_start();
$text = $_POST['message'];
$user = $_SESSION['username'];
$user2 = $_GET['user'];
$date = date('F j, Y, h:i A');
$con = mysql_connect("localhost","ZackBabtkis","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

mysql_query("INSERT INTO comments (`username`, `from`, `message`, `date`) 
VALUES ('$user2','$user','$text','$date')") or die('Error: ' . mysql_error());
mysql_close($con);
header("location: /users/$user2");
?>

 

If not, post all the code. Maybe the problem is somewhere else.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.