Reputation:
Right now I am working with a mysql database table. I have created a form that will input the data. The four fields that data is being entered are Class Caption
Class Name
Class Description
Credit Hours
. I have set an auto increment id
but every time I save a class I get an id
that equals 0
and for the class caption I get a .
period showing up infront. I am not sure why this issue is coming up every time I submit information into the database.
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);
}
?>
Insert Form
<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>
Table Design: LINK
QUERY
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)
);
Upvotes: 0
Views: 1206
Reputation: 91
Where is the auto increment defined? Shouldn't there be something like :
CREATE TABLE class
(
id int(11) NOT NULL AUTO_INCREMENT,...
Upvotes: 2