Adding a record to a database [message #175100] |
Mon, 15 August 2011 12:35 |
Charles
Messages: 13 Registered: February 2011
Karma:
|
Junior Member |
|
|
I'm trying to add a record to a database, and it's not working
properly.
The general thought is to call a data entry form, fill in the form,
and use the $_POST(array) process to pass the data from the form to a
php script that handles adding the record to the database.
The only trick part of the php script is using a hidden field to pass
the name of the data entry form to a SWITCH statement. I'm trying to
keep the site directory uncluttered and the scripting organized, and I
understand this works.
I'm getting Error 500 as I test the script, so I think I have
something coded incorrectly in the script, or I have something
missing. Other php-based web applications wrok fine, so I suspect I
have php correctly installed.
Here's the coding:
=====================
<?php
/* <!-- This starts the switch statement. The variable passed to
control iteration
is the $_Push(switch) variable set in the first (hidden) field in a
data entry form.
The value contained in the variable is the case predicate
*/
switch ($_Push(switch)) {
/*======================================================*/
case "cab_vehicle_data_entry_add_a_vehicle":
$con = mysql_connect("*********","****","******"); <<These are fine
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("taxicab", $con);
$sql="INSERT INTO
cab_vehicle (cab_vehicle_make, cab_vehicle_model,
cab_vehicle_edition,
cab_vehicle_month, cab_vehicle_year, cab_vehicle_VIN,
cab_vehicle_registration_number,
cab_vehicle_reg_exp_month, cab_vehicle_reg_exp_year,
cab_vehicle_pax_capacity,
cab_vehicle_cubic_feet_cargo, cab_vehicle_cargo_weight)
VALUES
('$_POST[Make]','$_POST[Model]','$_POST[Edition]','$_POST[Month]','$_POST[y ear]',
'$_POST[VIN]','$_POST[Registration]','$_POST[reg_exp_month]','$_POST[reg_ex p_year]',
'$_POST[pax_capacity]','$_POST[cargo_cubic_feet]','$_POST[cargo_weight_lbs] ') ";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
break;
/*======================================================*/
/* case "whatever"
Next process subroutine
break;
*/
/*======================================================*/
/* case "whatever"
Next process subroutine
break;
*/
/*======================================================*/
/* case "whatever"
Next process subroutine
break;
*/
/*======================================================*/
/* case "whatever"
Next process subroutine
break;
*/
/*======================================================*/
/* case "whatever"
Next process subroutine
break;
*/
/*======================================================*/
/* case "whatever"
Next process subroutine
break;
*/
/*======================================================*/
/* case "whatever"
Next process subroutine
break;
*/
/*======================================================*/
/* case "whatever"
Next process subroutine
break;
*/
}
?>
|
|
|