Page 1 of 1

Inserting data into a table

Posted: Thu May 28, 2009 11:30 am
by lmhart
Will someone please look at this and see if they can show me why two fields are not inserting into my table. I know the information is there because I also send an email out and all the information is present.

This is my insert statement. Everything is inserted except the phone and the date.

Code: Select all

 
<?php
 
include ("dbc.php");
 
 
mysql_query("INSERT INTO printers_table
                    (analyst,
                      crn_id,
                      contact_name,
                      phone,
                      email,
                      cost_center,
                      serial_number,
                      address,
                      reason,
                      date
                    )
                    VALUES
                    ('$_POST[analyst]',
                     '$_POST[crn_id]',
                     '$_POST[contact_name]',
                     '$_Post[phone]',
                     '$_POST[email]',
                     '$_POST[cost_center]',
                     '$_POST[serial_number]',
                     '$_POST[address]',
                     '$_POST[reason]',
                     '$_POST[date]'
                    )
            ")
                or
                die(mysql_error());
 
 
 
 
?>
 
Here is the code for the table

Code: Select all

 
CREATE TABLE `printers_table` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`analyst` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '',
`crn_id` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '',
`contact_name` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '',
`phone` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '',
`email` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '',
`cost_center` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '',
`serial_number` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '',
`address` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '',
`reason` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '',
`date` varchar(200) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
)
 
 

Re: Inserting data into a table

Posted: Thu May 28, 2009 11:50 am
by mikemike
Try some basic debugging such as echoing your query and $_POST. I can tell straight off that phone won't work becuase you're using $_Post[phone] instead of $_POST[phone].

Also, it's good practice to escape everything, and to not let PHP assume it's named keys. For example:
"INSERT INTO table (name, date, phone) VALUES ('$_POST[name]', '$_POST[date]'...
becomes:
"INSERT INTO table (name, date, phone) VALUES ('".$_POST['name']."', '".$_POST['date']."'...

You shoudl also escape these entries with something like mysql_real_escape_string()

Re: Inserting data into a table

Posted: Thu May 28, 2009 1:16 pm
by califdon
Your $_POST array indexes must be enclosed in quotes, like: $_POST['phone'].

Re: Inserting data into a table

Posted: Thu May 28, 2009 5:14 pm
by lmhart
mikemike wrote:Try some basic debugging such as echoing your query and $_POST. I can tell straight off that phone won't work becuase you're using $_Post[phone] instead of $_POST[phone].

That was the issue for the phone not submitting. However I still can not get the date to submit to the db.