I try to build my own website, and at my website I ask people to enter their name and write a little story. When they are done, they hit submit, and it sends the information to my database. I work with MySQL, and I want to create a table where I can store the information in. This is my MySQL code:
CREATE TABLE names (
name PRIMARY KEY NOT NULL,
message NOT NULL,
IPv4 NOT NULL,
browser NOT NULL,
date NOT NULL,
time NOT NULL,
);
But when I enter this in my command prompt, it says:
ERROR 1064 (42000): 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 'PRIMARY KEY NOT NULL, message NOT NULL,
IPv4 NOT NULL, browser NOT NULL, date NO' at line 1
Can you tell me what I did wrong and how to fix this? I don't know if it's helpful, but I've included my PHP script too. It can be a little messy with names because I had to translate the variables to English. My PHP code is (I created it before I created the table, and as you see I did manage to set up my database 'names', also I want to call my table 'names'):
$name = $_POST['name'];
$message = $_POST['message'];
$user = 'user';
$password = 'Login';
$host = 'localhost:3036';
$browser = $_SERVER['HTTP_USER_AGENT'];
$ip = $_SERVER["REMOTE_ADDR"];
date_default_timezone_set('UTC+1');
$date = date("Y-m-d");
$time = date("H:i:s");
$connect = mysql_connect($host, $user, $password);
if (! $connect)
{
$error = mysql_error();
print "Sorry, could not connect: $error";
}
print "Connected!";
$database = "USE names";
$table = "INSERT INTO names (name, message, IPv4, browser, date, time) VALUES ($name, $message, $ip, $browser, $date, $time)";
if (! $database)
{
$error=mysql_error();
echo "
Could not find database! Error: $mysql_error";
}
if (! $table)
{
$error=mysql_error();
echo "
Could not write to database! Error: $error";
}
$close = mysql_close($connect);
if (! $close )
{
$error=mysql_error();
echo "
Could not close connection! Error: $error";
}
echo "
Bedankt $name!";