MikeL7 Posted June 18, 2007 Share Posted June 18, 2007 I have made pages to create databases and the db gets created, but if i specify a not null auto_increment ,primary key the script ignores it and just makes the column a int column. Any help to make the script work would ge great. I am using php 5.2.3 here is the Code: <? $db_name = "$_POST[db_name]"; $connection = @mysql_connect("localhost", "user", "password") or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $sql = "CREATE TABLE $_POST[table_name] ("; for ($i = 0; $i < count($_POST[field_name]); $i++) { $sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i]; if ($_POST[auto_increment][$i] == "Y") { $additional ="NOT NULL auto_increment"; } else { $additional =""; } if ($_POST[primary][$i] == "Y") { $additional .=", primary key (".$_POST[field_name][$i].")"; } else { $additional =""; } if ($_POST[field_length][$i] != "") { $sql .="(".$_POST[field_length][$i].")$additional ,"; } else { $sql .="$additional ,"; } } $sql = substr($sql,0,-1); $sql .= ")"; $result = mysql_query($sql,$connection) or die(mysql_error()); if ($result) { $msg = "<P>$_POST[table_name] has been created!</p>"; } ?> Heres the form section that send the primary and auto_increment choices: <tr> <td <align=center><input type=\"text\" name =\"field_name[]\" size=\"30\"></td> <td> <align=center> <select name=\"field_type[]\"> <option value=\"char\">char</option> <option value=\"date\">date</option> <option value=\"float\">float</option> <option value=\"int\">int</option> <option value=\"text\">text</option> <option value=\"char\">varchar</option> </select> </td> <td align=center><input type=\"text\" name=\"field_length[]\" size=\"5 \"></td> <td ALIGN=CENTER><input type=\"checkbox\" name=\"primary[]\" value=\"Y \"></td> <td ALIGN=CENTER><input type=\"checkbox\" name=\"auto_increment[]\" value=\"Y \"></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/56119-conditional-statement-help/ Share on other sites More sharing options...
teng84 Posted June 18, 2007 Share Posted June 18, 2007 auto increment is always not null and from the word auto theres no way to vacate the fields Quote Link to comment https://forums.phpfreaks.com/topic/56119-conditional-statement-help/#findComment-277198 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.