Changing the value using a loop
Posted: Tue Jul 25, 2006 11:32 am
Hi all
sorry if this is to much to ask for but i need help on this
I will have a box where you type in how many fields you want in your database and then it will give you that many boxes see picture.
the picture has one row say i asked for 5 rows it would give you 5 rows of boxes

here is my code for the form and the proccess to add the table
thanks reece
sorry if this is to much to ask for but i need help on this
I will have a box where you type in how many fields you want in your database and then it will give you that many boxes see picture.
the picture has one row say i asked for 5 rows it would give you 5 rows of boxes
here is my code for the form and the proccess to add the table
Code: Select all
<form name="form1" method="post"
action="maketable.php">
<label>
Table Name </label>
<p>
<input name="tbname" type="text" id="tbname">
</p>
<p> </p>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#CCCCCC">
<tr>
<td width="30">Field</td>
<td width="144"><div align="center">Name</div></td>
<td width="144"><div align="center">Length</div></td>
<td width="201"><div align="center">Attributes</div></td>
<td width="80">Null</td>
<td width="81">Default</td>
<td width="81">Extra</td>
</tr>
<tr>
<td>1</td>
<td><input name="field1" type="text" id="field1"></td>
<td><input name="length1" type="text" id="length1"></td>
<td><select style="font-size: 70%;" name="attribute1" id="field_0_5">
<option value="" selected="selected"></option>
<option value="UNSIGNED">UNSIGNED</option>
<option value="UNSIGNED ZEROFILL">UNSIGNED ZEROFILL</option>
<option value="ON UPDATE CURRENT_TIMESTAMP">ON UPDATE CURRENT_TIMESTAMP</option>
</select></td>
<td><select name="null1" id="field_0_6">
<option value="NOT NULL" selected="selected" >not null</option>
<option value="">null</option>
</select></td>
<td><input id="field_0_7" type="text" name="default1" size="12" value="" class="textfield" /></td>
<td><select name="extra1" id="field_0_8">
<option value=""></option>
<option value="AUTO_INCREMENT">auto_increment</option>
</select></td>
</tr>
</table>
<p>
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</p>
</form>
///here is my php that gets the values of these and then creates a table
<?
//conection stuff
$table=$_POST['tbname'];
$field1=$_POST['field1'];
$field2=$_POST['field2'];
$field3=$_POST['field3'];
$length1=$_POST['$length1'];
$length2=$_POST['$length2'];
$length3=$_POST['$length3'];
$attribute1=$_POST['$attribute1'];
$attribute2=$_POST['$attribute2'];
$attribute3=$_POST['$attribute3'];
$maketable="CREATE TABLE $table(
$field1 varchar($length1) $attribute1 NOT NULL default '',
$field2 varchar($length2) $attribute2 NOT NULL default '',
$field3 varchar($length3) $attribute3 NOT NULL default '')";
//so this would be if you had a 3 field table i would need to make it so this would make it for as many rows you have chosen sorry if i have not explained it well
$domaketable=mysql_query($maketable);
if ($domaketable) {
echo "Created $tbname";
}
else
{
echo "Error $tbname";
}
?>thanks reece