[PHP/MySQL] Creating a Table with Auto Increment
| From: | David Snowden | Date: | Thu, 26 Oct 2000 18:38:01 +0000 |
| Subject: | [PHP/MySQL] Creating a Table with Auto Increment | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-22186@lists.php.net to get a copy of this message | ||
When i create a table using this html form, i always make my first field an
ID.
And i want it to be auto-incremented so i dont have to type an id in and
remember which one is next every time i add a record...
What can i add to the source of this php file that will allow me to do this?
I dont know what to put under the select menu that is used to define the
field type... i was thinking this:
<option value=\"INT NOT NLL AUTO_INCREMENT\">auto_increment</option>
but i doubt that is right.
Any help is appreciated :)
Dave
Here is the code....
<! -- start php page -->
<?
if ((!$table_name) || (!$num_fields)) {
header("Location:
http://zeus.jtlnet.com/~devphpc/manager/show_createtable1.html");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>phpdev.com mySQL manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#CCCCCC" leftmargin="0" topmargin="0"
marginwidth="0"
marginheight="0" text="#000000" link="#66CCFF"
vlink="#66CCFF">
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr bgcolor="#333333">
<td width="2%"> </td>
<td width="63%">
<div align="left"><img src="images/phpdev_logo.gif"
width="143"
height="30"></div>
</td>
<td width="9%"> </td>
<td width="26%"><img src="images/phpdev_mysqlmanager.gif"
width="188"
height="30"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="2%"> </td>
<td width="63%" valign="top">
<FORM method="POST" action="do_createtable.php">
<br>
<img src="images/phpdev_createtable2.gif" width="200"
height="14"><br>
<hr width="200" align="left">
<img src="images/phpdev_definefields.gif"> <font size="-1"
face="verdana"><b><?php echo "$table_name";
?></b></font>
<br>
<p><INPUT type="hidden" name="table_name" value="<?php
echo
"$table_name"; ?>">
</p>
<p>
<table bgcolor="#0066ff" cellspacing=5 cellpadding=5>
<tr bgcolor="#ffffff">
<th><img src="images/phpdev_fieldname.gif"></th><th><img
src="images/phpdev_fieldtype.gif"></th><th><img
src="images/phpdev_fieldlength.gif"></th></tr>
<?
for ($i = 0 ; $i <$num_fields; $i++) {
echo "
<tr>
<td align=center>
<input type=\"text\" name=\"field_name[]\" size=\"30\">
</td>
<td align=center>
<select name=\"field_type[]\">
<option value=\"\">-- select type --</option>
<option value=\"float\">float</option>
<option value=\"int\">int</option>
<option value=\"text\">text</option>
<option value=\"varchar\">varchar</option>
</select>
</td>
<td align=center>
<input type=\"text\" name=\"field_length[]\" size=\"5\">
</td>
</tr>";
}
?>
<tr><td align=center colspan=3><INPUT type="submit" value="Create
Table"></td></tr>
</table>
</p>
<p> </p>
</form>
</td>
<td width="9%"> </td>
<td width="26%"> </td>
</tr>
</table>
</BODY>
</HTML>
<! -- END PAGE -->