I have the following code:
<?php
session_start();
require_once('inc/db_connect.php');
// initialize extra variables
$gender = '';
$wait_list = '';
$referral = '';
if (isset($_POST['org_name'])) {
$date_submitted = date('Y-m-d');
$date_modified = '0000-00-00';
// echo $date_submitted;
//Profile Information
$org_name = $_POST['org_name'];
$org_type = $_POST['org_type'];
$prog_name = $_POST['prog_name'];
$hours = $_POST['hours'];
$url = $_POST['url'];
$address = $_POST['address'];
$city = $_POST['city'];
$province = $_POST['province'];
$postal = $_POST['postal'];
$main_phone = $_POST['main_phone'];
$tollfree = $_POST['tollfree'];
$contact_name = $_POST['contact_name'];
$contact_position = $_POST['contact_position'];
$directline = $_POST['directline'];
$cell = $_POST['cell'];
$email = $_POST['email'];
//General Information
$age = $_POST['age'];
$gender = $_POST['gender'];
$religion = $_POST['religion'];
$disabilities = $_POST['disabilities'];
$addictions = $_POST['addictions'];
$min_require = $_POST['min_require'];
$prereq = $_POST['prereq'];
$wait_list = $_POST['wait_list'];
$referral = $_POST['referral'];
$usage_fee = $_POST['usage_fee'];
$admission_fee = $_POST['admission_fee'];
$languages = $_POST['languages'];
$geo_area = $_POST['geo_area'];
$volunteers = $_POST['volunteers'];
$core_comp = $_POST['core_comp'];
$other = $_POST['other'];
if ($org_name == '') {
header('location:form.php?msg=n');
exit();
}
$data = array(
':date_submitted' => $date_submitted,
':date_modified' => $date_modified,
':org_name' => $org_name,
':org_type' => $org_type,
':prog_name' => $prog_name,
':hours' => $hours,
':url' => $url,
':address' => $address,
':city' => $city,
':province' => $province,
':postal'=> $postal,
':main_phone' => $main_phone,
':tollfree' => $tollfree,
':contact_name' => $contact_name,
':contact_position' => $contact_position,
':directline' => $directline,
':cell' => $cell,
':email' => $email,
':age' => $age,
':gender' => $gender,
':religion' => $religion,
':disabilities' => $disabilities,
':addictions' => $addictions,
':min_require' => $min_require,
':prereq' => $prereq,
':wait_list' => $wait_list,
':referral'=> $referral,
':usage_fee' => $usage_fee,
':admission_fee' => $admission_fee,
':languages' => $languages,
':geo_area' => $geo_area,
':volunteers' => $volunteers,
':core_comp' => $core_comp,
':other' => $other
);
echo '<pre>';
print_r($data);
echo '</pre>';
// insert the data
$query = "INSERT INTO organizations ( date_submitted, date_modified, org_name, org_type, prog_name, hours, url, address, city, province, postal, main_phone, tollfree, contact_name, contact_position, directline, cell, email, age, gender, religion, disabilities, addictions, min_require, prereq, wait_list, referral, usage_fee, admission_fee, languages, geo_area, volunteers, core_comp, other )
VALUES ( :date_submitted, :date_modified, :org_name, :org_type, :prog_name, :hours, :url, :address, :city, :province, :postal, :main_phone, :tollfree, :contact_name, :contact_position, :directline, :cell, :email, :age, :gender, :religion, :disabilities, :addictions, :min_require, :prereq, :wait_list, :referral, :usage_fee, :admission_fee, :languages, :geo_area, :volunteers, :core_comp, :other )
";
$stmt = $db->prepare($query);
echo $query;
// perform the database query
$stmt->execute($data);
echo "New form submission id: " . $db->lastInsertId();
//header('location: form.php?msg=y');
//exit;
- I populated the database a few weeks ago with a form that uses this form_handler. It worked fine at the time.
- Now it does not insert entries into the database, although a file used to update the database, using mostly the same code, does work.
- My
echo $query
doesn’t tell me anything, because it just prints out the query with the placeholders. - My
echo "New form submission id: " . $db->lastInsertId();
gives me a value of 0; - My
print_r($data);
is showing the correct entries that I want to insert into the database.
Can you see what went wrong with my code?