I am trying to run the following query, but am getting a sql syntax error, but dreamweaver doesnt seem to be highlighting any error so im not sure where it is ?.
thanks 🙂
<?php
$form_id = $_POST[form_id];
$query = mysql_query("
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'email_history'
AND COLUMN_NAME = `$form_id`)
BEGIN
ALTER TABLE 'email_history' ADD `$form_id` VARCHAR( 255 ) NOT NULL
END;
") or die(mysql_error());
?>
Everyone has focused on bad quoting, but is there any chance of this query to run? Does MySQL allow such conditional statements? I know this is possible in stored routines but I have never heard of such direct usage, so I would split this into two queries: column existence check and table alteration.
This will look like this: