Advertisement

04.22.2008 at 09:11PM PDT, ID: 23345450
[x]
Attachment Details

Using ID in a form and have it increment

Asked by stl-it in PHP and Databases, MySQL

Tags: PHP MySQL, IE

I've been reading all of the tutorials that I can find, but I can't figure out the most basic thing.

I have a very simple script that I want to use to update a db called sanderan_test.  I have 5 fields. Id, name, short_info, description, and modified.

My form passes the name, short_info, and description over to the php. I understand that and have made it work without having an ID field. Now I want to have it update the ID field. I have the ID field set as an INT in the table and have it set to auto_increment.  How do I get it to increment? Does my php need to tell it to do this or am I trying to fix something that isn't broken?  I'm not able to write any records to the db but not getting any errors.   My php isn't calling the ID or Modified fields, I'm under the assumption these are automatically updated.
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
<?php
// Open database connection
$conn = mysql_connect('localhost', 'sanderan_usernam', 'password') or die("Unable to connect, the reason is: " . mysql_error());
mysql_select_db('sanderan_test') or die("Could not select database, the reason is: " . mysql_error());
 
// Pick up the form data and assign it to variables (if it was submitted)
if ($_POST['Status'] == '1') {
$name = $_POST['name'];
$short_info = $_POST['short_info'];
$description = $_POST['description'];
 
 
// Insert data
$query = "INSERT INTO my_new_table ('name', 'short_info', 'description')
  VALUES ('$name', '$short_info', '$description')";
mysql_query($query);
 
 
// Close connection
mysql_close($conn);
 
// Redirect
header("Location: success.html");
}
 
?>
[+][-]04.22.2008 at 09:39PM PDT, ID: 21417814

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.22.2008 at 10:13PM PDT, ID: 21417902

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, MySQL
Tags: PHP MySQL, IE
Sign Up Now!
Solution Provided By: NesFuratu
Participating Experts: 2
Solution Grade: B
 
 
[+][-]04.23.2008 at 06:20AM PDT, ID: 21420326

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628