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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.