Jump to content

HELP!! - mysql database/php help


shmickvl

Recommended Posts

Hi guys

im having some trouble.
i create a table in phpmyadmin, with two fields for example: id and name. i set my id field to auto increment, not null, and the primary key. i have made a "index.html" form to submit data, and made my "submission.php" page which takes it all there. The problem is that in my table, if i have the id field, data will not go to the database. However, if i delete the id field, it will go there.

PLease help

attached are my codes.

<html>
<body>
<form action="submission.php" method="post">
First Name: <input type="text" name="name"><br>
<input type="Submit">
</form>
</body>
</html>


<?
$name=$_POST['name'];
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("example") or die(mysql_error());
mysql_query("INSERT INTO `example1` VALUES ('$name')");
Print "Your information has been successfully added to the database.";
?>


cheers for your help
Link to comment
https://forums.phpfreaks.com/topic/15316-help-mysql-databasephp-help/
Share on other sites

When you use this syntax
[code]
mysql_query("INSERT INTO `example1` VALUES ('$name')");
[/code]

you must supply values for all the fields in the right order, even if one of them is auto-incremented, so if your id field is first in the table for example:

[code]
mysql_query("INSERT INTO `example1` VALUES (NULL, '$name')");
[/code]

the NULL will be replaced by the auto-increment value.

Or you could use the syntax
[code]
mysql_query("INSERT INTO `example1` (name) VALUES ('$name')");
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.