Using ALTER in php script?
I need to be able to ADD a new column to my mysql database table, when a new 'date' is created for a mailing list i.e. list_2004-12-15 as a column name, but am unsure on how to go about getting the code correct to allow this sort of query to be executed.
I tried a couple of times with output from phpmyadmin but it just gave expecting ` errors.
Any help as ever, appreciated.
You might want to have a look at the alter table page in the MySQL manual.
So this doesn't work:
$mailing_name = $mname . _ . $date;
$update_add_mailingname = mysql_query("ALTER TABLE emails ADD $mailing_name ENUM('N','Y') DEFAULT 'N'");
But the below does add a table, just not with the name of the name of the variable.
$mailing_name = $mname . _ . $date;
$update_add_mailingname = mysql_query("ALTER TABLE emails ADD mailing_240904 ENUM('N','Y') DEFAULT 'N'");
So how would I get it to add it with the variable as the table name?
What table name gets added? Did you echo the value of $mailing_name to see if that is what you expect?
It just gives me an error message which I put in if the query does not execute successfully...
I know the value of $mailing_name is as expected as it inputs this correctly into the database record of the mailing name.
I fixed it.
The problem was due to the mysql_query before the first ("
Removing mysql_query fixed it.
Strange, I thought I had tried it that way before and it errored.
Oh well!
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks