[thelist] creating a mySQL table dynamically in php

Seth Fitzsimmons thelist at lists.evolt.org
Mon Jan 6 15:08:00 2003


Tom Dell'Aringa wrote:
> I'm trying to create a table in my DB with a script. Here is the
> code:
> -----------------
> // connection stuff
>
> $sql  = " CREATE TABLE test  (";
> $sql .= "   pid    VARCHAR(12), ";
> $sql .= "   qty    VARCHAR(12), ";
> $sql .= " );  ";
>
> if(!@mysql_query($sql))
> {
> 	print "Err" . mysql_error();
> 	exit();
> }
> -----------------
>
> I don't get the table, I keep getting this type of error:
>
> You have an error in your SQL syntax near '); ' at line 1
>
> I tried putting it all together in one line with no success. I'm not
> sure where the quotes go but I figure it is that kind of
> error..anyone?

Try getting rid of the second comma (qty VARCHAR(12)).  Also make sure
that you're not using tabs in the quoted string that eventually gets
passed to mysql.

seth