netpants Posted December 18, 2006 Share Posted December 18, 2006 Alright well I have a simple input form for php, its like an address book. But my problem is I didnt add an ID table to the database before, and I just added one. I need to set it up so that it automaticly adds +1 to the ID field. Look here. http://www.freegamespot.net/dancefactory/display.phpOn the first column there is an ID field, I put in those IDS, but I need php to automaticly add +1 to every new entry for the ID field. Here is my code.[code]<?$username="";$password="";$database="";mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$id=$_POST['id'];$date=$_POST['loggedDate'];$first=$_POST['firstName'];$last=$_POST['lastName'];$birth=$_POST['birth'];$phone=$_POST['phone'];$streetnumber=$_POST['streetNumber'];$streetname=$_POST['streetName'];$city=$_POST['city'];$state=$_POST['state'];$zip=$_POST['zip'];$prize=$_POST['prize'];++$id;$query = "INSERT INTO Winners VALUES ('$id','$date','$first','$last','$birth','$phone','$streetnumber','$streetname','$city','$state','$zip','$prize')";mysql_query($query);mysql_close();?><form action="insert.php" method="post"><input type="hidden" name="id" value="<? echo $id; ?>">Date: <input type="text" name="loggedDate"> <br>First Name: <input type="text" name="firstName"> <br>Last Name: <input type="text" name="lastName"><br>Birthdate: <input type="text" name="birth"><br>Phone Number: <input type="text" name="phone"><br>Street Number: <input type="text" name="streetNumber"><br>Street Name: <input type="text" name="streetName"><br>City: <input type="text" name="city"><br>State: <input type="text" name="state"><br>Zip Code: <input type="text" name="zip"><br>Prize: <input type="text" name="prize"><br><input type="Submit"></form>[/code]Is this correct? If not what is wrong and how do I make it add the +1 to the ID field for every new entry. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted December 18, 2006 Share Posted December 18, 2006 If you set up a column in your MySQL database to be 'id' then all you need to do is set that field's properties to AUTO-INCREMENT and it will automatically add 1 each time a new entry is inserted into that table. You can pull that id # in any display as well. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 18, 2006 Share Posted December 18, 2006 Set the field to autoincrement in MySQL.Ken Quote Link to comment Share on other sites More sharing options...
netpants Posted December 18, 2006 Author Share Posted December 18, 2006 Thank you, my problem is fixed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.