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. Link to comment https://forums.phpfreaks.com/topic/31128-solved-adding-1-to-an-id-table/ 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. Link to comment https://forums.phpfreaks.com/topic/31128-solved-adding-1-to-an-id-table/#findComment-143735 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 Link to comment https://forums.phpfreaks.com/topic/31128-solved-adding-1-to-an-id-table/#findComment-143736 Share on other sites More sharing options...
netpants Posted December 18, 2006 Author Share Posted December 18, 2006 Thank you, my problem is fixed. Link to comment https://forums.phpfreaks.com/topic/31128-solved-adding-1-to-an-id-table/#findComment-143799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.