基本的に、$_SESSIONS を使用してユーザーが入力した値を持ち運ぶ複数ページのフォームを作成しました。私の最後のページは、データベースに入力せずにすべてのセッション値を表示する確認ページだったので、セッション変数は機能します。確認ページに続くphpページはこちら。
<?php
session_start();
if($_POST['formSubmit'] == "Confirm")
{
$errorMessage = "";
$varFirstName=$_SESSION['firstname'];
$varLastName=$_SESSION['lastname'];
$varBirthdate=$_SESSION['birthdate'];
$varSex=$_SESSION['sex'];
$varHealthCardPart1=$_SESSION['healthcardpart1'];
$varHealthCardPart2=$_SESSION['healthcardpart2'];
$varHealthCardPart3=$_SESSION['healthcardpart3'];
$varHealthCardPart4=$_SESSION['healthcardpart4'];
$varSpecialInterests=$_SESSION['specialInterests'];
$varSpecialConsiderations=$_SESSION['specialConsiderations'];
$adultFirstName1=$_SESSION['adultFirstName1'];
$adultLastName1=$_SESSION['adultLastName1'];
$relationship1=$_SESSION['relationship1'];
$adultFirstName2=$_SESSION['adultFirstName2'];
$adultLastName2=$_SESSION['adultLastName2'];
$relationship2=$_SESSION['relationship2'];
$familyAddress=$_SESSION['familyaddress'];
$unit=$_SESSION['unit#'];
$postalCode=$_SESSION['postalCode'];
$city=$_SESSION['city'];
$homeNumber = $_SESSION['home#'];
$workNumber= $_SESSION['work#'];
$emailAddress = $_SESSION['email'];
$emergencyFirstName1 = $_SESSION['emergencyContactFirstName1'];
$emergencyLastName1 = $_SESSION['emergencyContactLastName1'];
$emergencyContactPhone1 = $_SESSION['econtactphone1'];
$emergencyContactRelationship1 = $_SESSION['erelationship1'];
$emergencyFirstName2 = $_SESSION['emergencyContactFirstName2'];
$emergencyLastName2 = $_SESSION['emergencyContactLastName2'];
$emergencyContactPhone2 = $_SESSION['econtactphone2'];
$emergencyContactRelationship2 = $_SESSION['erelationship2'];
$varPickedUp = $_SESSION['camperpickedup'];
$varPersonPickingUp = $_SESSION['personPickingUpCamper'];
$varTotalPrice = $_SESSION['totalPrice'];
$campcare = $_SESSION['campcare'];
$campsessions = $_SESSION['campsessions'];
if (empty($errorMessage))
{
$db= mysql_connect("localhost", "root", "root");
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db("onlineform", $db);
$sql = "INSERT INTO onlineformdata (firstname, lastname, birthdate, sex, healthcardpart1, healthcardpart2, healthcardpart3, healthcardpart4, specialinterests, specialconsiderations, firstNameOfAdult1, lastNameOfAdult1, adult1RelationshipToChild, firstNameOfAdult2, lastNameOfAdult2, adult2RelationshipToChild, address, apartmentNumber, postalCode, city, homeNumber, workNumber, emailAddress, emergencyContact1FirstName, emergencyContact1LastName, emergencyContact1PhoneNumber, emergencyContact1RelationshipToChild, emergencyContact2FirstName, emergencyContact2LastName, emergencyContact2PhoneNumber, emergencyContact2RelationshipToChild, isCamperPickedUp, personPickingUpCamper, specificCampSessions, needCampCare, totalPrice) VALUES (". PrepSQL($varFirstName) . ", " . PrepSQL($varLastName) . ", " . PrepSQL($varBirthdate) . "," . PrepSQL($varSex) . "," . PrepSQL($varHealthCardPart1) . "," . PrepSQL($varHealthCardPart2) . "," . PrepSQL($varHealthCardPart3) . "," . PrepSQL($varHealthCardPart4) . "," . PrepSQL($varSpecialInterests) . "," . PrepSQL($varSpecialConsiderations) . PrepSQL($adultFirstName1) . ", " . PrepSQL($adultLastName1) . ", " . PrepSQL($relationship1) . "," . PrepSQL($adultFirstName2) . "," . PrepSQL($adultLastName2) . "," . PrepSQL($relationship2) . "," . PrepSQL($familyaddress) . "," . PrepSQL($unit) . "," . PrepSQL($postalCode) . "," . PrepSQL($city) . "," . PrepSQL($homenumber) . "," . PrepSQL($worknumber) . "," . PrepSQL($emailAddress) . PrepSQL($emergencyFirstName1) . ", " . PrepSQL($emergencyLastName1) . ", " . PrepSQL($emergencyContactPhone1) . "," . PrepSQL($emergencyContactRelationship1) . "," . PrepSQL($emergencyFirstName2) . "," . PrepSQL($emergencyLastName2) . "," . PrepSQL($emergencyContactPhone2) . "," . PrepSQL($emergencyContactRelationship2) . PrepSQL($varPickedUp) . "," . PrepSQL($varPersonPickingUp) . PrepSQL($campsessions) . "," . PrepSQL($campcare) . PrepSQL($varTotalPrice) . ")";
mysql_query($sql);
}
}
function PrepSQL($value)
{
// Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
?>
そして私の問題は、データベース「onlineform」の下のテーブル「onlineformdata」に入力されていないことです。確認ページには、タグで囲まれた「確認」という名前のボタンがあります。この問題を解決して、MySQL サーバーに保存できるようにするにはどうすればよいですか? ありがとうございました。