<?php
$selected_db='naughty';
$username=$_POST['username'];
$offence=$_POST['offence'];
$punishment= $_POST['punishment'];
$con=mysql_connect('localhost','root','panda')or die (mysql_error());
include 'error.php';
include 'database.php';
if (!$con)
{
die('could not connect: ' . mysql_error());
}
mysql_select_db("naughtylist") or die(mysql_error());
mysql_query ("CREATE TABLE watchlist
username VARCHAR(16) NOT NULL,
offence TEXT NOT NULL,
punishment TEXT NOT NULL,
PRIMARY KEY (username)
")
or die (mysql_error());
$result=mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
?>
I am getting an error for this code, with the error concerning the syntax at:
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 'username VARCHAR(16) NOT NULL, offence TEXT NOT NULL, punishment TEXT NOT NULL' at line 2
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
Aren't you missing the parenthesis around the column definitions? Try:
CREATE TABLE watchlist
(username VARCHAR(16) NOT NULL,
offence TEXT NOT NULL,
punishment TEXT NOT NULL,
PRIMARY KEY (username))
try this:
mysql_query("CREATE TABLE watchlist (username varchar(16) not null, primary key(username), offence text not null, punishment text not null)")
Is INT meant to be Integer? I additionally do no longer see INT or DEFAULT as parameters interior the synopsis of the declare assertion. Nowhere did I see Integer no longer spelled out. yet then i've got no longer messed with postgresql so i could desire to be thoroughly out in left container.