现在我正在使用mysql数据库表。我创建了一个输入数据的表单。输入数据的四个字段是Class Caption
Class Name
Class Description
Credit Hours
。我设置了自动增量id
,但每次保存课程时,我都会获得等于id
的{{1}},而对于课程标题,我会看到0
期间出现。我不确定为什么每次我向数据库提交信息时都会出现这个问题。
PHP
.
插入表单
<h1>class</h1>
<?php
include ('Resources/db_connect.php');
$query="SELECT * FROM class";
$result=mysql_query($query, $db_link);
if ($result){
$num=mysql_num_rows($result);
mysql_close();
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td><h3>id</h3></td>
<td><h3>class_caption</h3></td>
<td><h3>class_name</h3></td>
<td><h3>class_description</h3></td>
<td><h3>class_credit_hours</h3></td>
</tr>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"id");
$f2=mysql_result($result,$i,"class_caption");
$f3=mysql_result($result,$i,"class_name");
$f4=mysql_result($result,$i,"class_description");
$f5=mysql_result($result,$i,"class_credit_hours");
?>
<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
<td><?php echo $f5; ?></td>
</tr>
<?php
$i++;
}
}
else{
echo "No Results Found";
mysql_close($db_link);
}
?>
表格设计:LINK
QUERY
<form action="" method="post">
<table>
<tr>
<td>Class Caption: <td><input type="text" name="class_caption" size="8"><br>
</tr>
<tr>
<td>Class Name: <td><input type="text" name="class_name" size="30"><br>
</tr>
<tr>
<td>Class Description: <td><textarea rows="5" name="class_description" cols="50"></textarea><br>
</tr>
<tr>
<td>Credit Hours: <td><input type="text" name="class_credit_hours" size="1">
</tr>
<tr>
<td><input type="submit" value="Submit">
</tr>
</table>
</form>
答案 0 :(得分:3)
自动增量定义在哪里? 不应该有这样的东西:
CREATE TABLE class
(
id int(11) NOT NULL AUTO_INCREMENT,...