Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.