0

现在我正在使用 mysql 数据库表。我创建了一个输入数据的表单。正在输入数据的四个字段是Class Caption Class Name Class Description Credit Hours。我已经设置了一个自动增量id,但是每次我保存一个类时,我都会得到一个id等于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);
}
?>

插入表格

<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>

表设计链接

询问

CREATE TABLE class
(
    id INT,
    class_caption VARCHAR(30),
    class_name VARCHAR(30),
    class_description VARCHAR(300),
    class_credit_hours INT,
    CONSTRAINT cc_pk PRIMARY KEY (id),
    CONSTRAINT cc_uq UNIQUE (class_caption)
);
4

1 回答 1

3

自动增量在哪里定义?不应该有类似的东西:

CREATE TABLE class
(
id int(11) NOT NULL AUTO_INCREMENT,...
于 2012-11-13T13:39:05.893 回答