In WAMP and in phpMyadmin I created a database called PROJECT with this table
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(25) NOT NULL,
`password` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
I am trying to test the following code:
<?php
$con=mysql_connect ("localhost","******","");
mysql_select_db("project",$con);
@$a=$_POST['txt1'];
@$b=$_POST['txt2'];
if(@$_POST['inser'])
{
$s="INSERT INTO users VALUES ('','$a','$b')";
echo "Your Data Inserted";
mysql_query ($s);
}
$con=mysql_connect ("localhost","******","");
mysql_select_db ("project",$con);
if(@$_POST ['sel'])
{
echo $ins=mysql_query ("select * from users");
echo "<table bgcolor=skyblue border='2'>
<tr>
<th colspan=4>Display details</th></tr>
<tr>
<th>ID</th>
<th>Username</th>
<th>Password</th>
</tr>";
while ($row=mysql_fetch_array ($ins))
{
echo "<tr>";
echo "<th>".$row ['id']."</th>";
echo "<th>".$row ['username']."</th>";
echo "<th>". $row ['password']. "</th>";
echo "</tr>";
}
}
echo "</table>"
?>
<html>
<head>
</head>
<body bgcolor="pink">
<table bgcolor="skyblue" border="2">
<form method="post">
<tr>
<td colspan=2 align="center">Details</td>
</tr>
<td>Username</td><td><input type="text" name="txt1"></td>
</tr>
<tr>
<td>Password</td><td><input type="text" name="txt2"></td>
</tr>
<tr>
<td><input type="submit" name="inser" value="Insert"></td>
<td><input type="submit" name="sel" value="Select"></td>
</tr>
</form>
</table>
</body>
</html>
When I insert manually username and password in the database and click the Select button then I have the record. When I try to insert a record using the INSERT INTO above it is impossible to add the record. I have the message YOUR DATA INSERTED but there is no record in the database. I tried it without the field ID and it works perfect. I tried it also without AUTO INCREMENT but without results. So what is the problem with the ID?