php - Failing to create mySQL table -


i'm trying create table if not exist in database. i'm running test working intended:

$conn = mysql_connect("localhost", "twa222", "twa222bg"); mysql_select_db("airline222", $conn) or die ("database not found " . mysql_error() ); $val = mysql_query("select 1 '$flightid'"); 

however problem comes when try create table itself, giving me following error: problem query: you have error in sql syntax; check manual corresponds mysql server version right syntax use near ''passenger' smallint not null, 'booking' char(6), 'seat' varchar(3))' @ line 2

this code attempting generate table

if(!$val) {     $sql = "create table ".$flightid." (     passenger smallint not null primary key,     booking char(6), seat varchar(3) )";     $rs = mysql_query($sql) or die ("problem query" . mysql_error()); } mysql_close($conn); 

i thought ".$flightid." causing problem when changed abc still got same error.

can see going wrong?

edit: sql output when using abc is:

create table abc ( passenger smallint not null primary key, booking char(6), seat varchar(3) )

without using abc is:

create table ( passenger smallint not null primary key, booking char(6), seat varchar(3) )

you use single quotes arround column names not allowed. single qoutes indicates value inside litaral:

change:

$val = mysql_query("select 1 '$flightid'"); 

to:

$val = mysql_query("select 1 $flightid"); 

use mysqli_*or pdoinstead of deprecated mysql_* api.


Comments