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

<?php

session_start();

$_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"){

include('mysqlcon.php');

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


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

if(!$sql){
echo "error" . mysql_error();
}else{
header("location: index.php");
}

}else{

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 (`).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.