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();
}

?>

If the user_id data type is numeric, then it won't need single quotes in the sql.

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

This could also apply to the index, however since you are inserting an empty value, I would assume the datatype is not numeric.

thank you for your help. how dumb it was

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.