I found where the problem stems from after correcting a couple
items per your example but still don't know why it won't work.

It comes from using checkboxes in the form for PRIMARY KEY,
AUTO_INCREMENT and NOT NULL or NULL. When I use checkboxes
like this:

<td align=center>
<input type=\"checkbox\" name=\"not_null[]\" value=\"Y\">
</td>

it totally messes up the query. But when I use 

<td align=center>
<input type=\"text\" name=\"not_null[]\" size=1>
</td>

and either leave it blank or enter "Y" it works fine! This
is really driving me nuts and I'm afraid it's going to be
something stupid staring me in the face.
Jeff Oien

> Quick example...
> 
> CREATE TABLE user (
>    userid int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
>    usergroupid smallint(5) unsigned DEFAULT '0' NOT NULL,
>    username varchar(50) NOT NULL,
>    password varchar(50) NOT NULL,
>    email varchar(50) NOT NULL,
>    parentemail varchar(50) NOT NULL,
>    coppauser smallint(6) DEFAULT '0' NOT NULL,
>    homepage varchar(100) NOT NULL,
>    icq varchar(20) NOT NULL,
>    aim varchar(20) NOT NULL,
>    yahoo varchar(20) NOT NULL,
>    biography mediumtext NOT NULL,
>    signature mediumtext NOT NULL,
>    adminemail smallint(6) DEFAULT '0' NOT NULL,
>    showemail smallint(6) DEFAULT '0' NOT NULL,
>    invisible smallint(6) DEFAULT '0' NOT NULL,
>    usertitle varchar(250) NOT NULL,
>    customtitle smallint(6) DEFAULT '0' NOT NULL,
>    joindate int(10) unsigned DEFAULT '0' NOT NULL,
>    canpost smallint(6) DEFAULT '0' NOT NULL,
>    cookieuser smallint(6) DEFAULT '0' NOT NULL,
>    daysprune smallint(6) DEFAULT '0' NOT NULL,
>    lastvisit int(10) unsigned DEFAULT '0' NOT NULL,
>    lastactivity int(10) unsigned DEFAULT '0' NOT NULL,
>    lastpost int(10) unsigned DEFAULT '0' NOT NULL,
>    posts smallint(5) unsigned DEFAULT '0' NOT NULL,
>    timezoneoffset smallint(6) DEFAULT '0' NOT NULL,
>    emailnotification smallint(6) DEFAULT '0' NOT NULL,
>    imgurl varchar(150) NOT NULL,
>    PRIMARY KEY (userid),
>    KEY idxgroups (username, usergroupid)
> );
> 
> -----Original Message-----
> From: Jeff Oien [mailto:[EMAIL PROTECTED]]
> Sent: Friday, March 02, 2001 2:09 PM
> To: PHP
> Subject: [PHP] MySQL Create Table Problem
> 
> 
> This is driving me nuts. I really tried to figure it out
> myself. I have a form for creating a table. The form
> fields have field_name field_type field_length, and
> checkboxes for not_null, auto_increment and primary.
> 
> When I check the primary key checkbox it always makes
> the first field the primary key no matter what. And it
> makes two date fields I enter NULL and the rest NOT
> NULL no matter what I put in the checkboxes. The code
> is below along with a printout of the SQL query. I only
> wanted suffix and death date to be null. This is combination
> from PHP Fast and Easy and MySQL by Dubois.
> 
> $sql = "CREATE TABLE $table_name (";
> 
> for ($i = 0; $i < count($field_name); $i++) {
> 
>       $sql .= "$field_name[$i] $field_type[$i]";
> 
>       if ($not_null[$i] == "Y") {
>               $additional = " NOT NULL";
>       } else {
>               $additional = " NULL";
>       }
> 
>       if ($auto_increment[$i] == "Y") {
>               $additional .= " AUTO_INCREMENT";
>       } else {
>               $additional .= "";
>       }
> 
>       if ($primary[$i] == "Y") {
>               $additional .= " primary key";
> 
>       } else {
>               $additional .= "";
>       }
> 
>       if ($field_length[$i] != "") {
>               $sql .= "($field_length[$i]) $additional,";
>       } else {
>               $sql .= " $additional,";
>       }
> 
> }
> 
> $sql = substr($sql, 0, -1);
> 
> $sql .= ")";
> 
> ------------
> 
> CREATE TABLE president (last_name varchar(15) NOT NULL primary
> key,first_name
> varchar(15) NOT NULL,suffix varchar(5) NOT NULL,city varchar(20) NOT
> NULL,state
> varchar(2) NOT NULL,birth date NULL,death date NULL)
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to