i get this 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 'index, user_id, username, message) VALUES(' ', '4', 'zack', 'jh')' at line 1



$_SESSION['user_id'] = 4;

$user_id = $_SESSION['user_id'];

$_SESSION['username'] = "zack";

$username = $_SESSION['username'];

$message = $_POST['shout_mes'];

$insert = $_POST['shout'];

if(!empty($message) && $insert = "shout"){


$select = mysql_select_db($db, $con);
die('could not select db: ' . mysql_error());

$sql = mysql_query("INSERT INTO shoutbox (index, user_id, username, message) VALUES(' ', '$user_id', '$username', '$message')");

echo "error" . mysql_error();
header("location: index.php");


echo "there was an error: " . mysql_error();


'index' is a reserved word. You must name that column something else.

ok here is what worked.

$sql = mysql_query("INSERT INTO shoutbox (user_id, username, message) VALUES('$user_id', '$username', '$message')");

It is not a good habit to use reserve words as column or table names. But if you still need to use that then simply enclose the column name in backticks (`).