[SOLVED]Updating table, using SESSION to choose record
Posted: Thu Jun 10, 2004 1:38 pm
I'm creating a two part form that inputs the data into a mysql database table. I thought that to do this I would need to set a SESSION variable that would be the same as one of the database table fields (that would have a unique value) from the first page of the form, and then use that SESSION variable in the WHERE clause to make sure the correct record was updated (ie. had the second part of the form data added).
However, what I've done isn't working, and I'm having trouble figuring out why. Here's my code, in order:
The first page of the form:
The php script that processes that form:
The second form:
The php script that processes the second form, where I want the data added to the same record as the first part:
I'm not sure if I needed to post all of that, but since I don't know where the problem lies, I thought maybe I should.
Having said that, the error I'm getting is in the second php script, at the "$sql_morequalify =" line -- a parse error. But I don't know whether that's a problem with the sytax of that line, or the SESSION variable.
Any ideas?
Thanks,
Scott
However, what I've done isn't working, and I'm having trouble figuring out why. Here's my code, in order:
The first page of the form:
Code: Select all
<html>
<head>
<title>Initial Questions-Part 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#333399">
<table width="600" border="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#C5C5EB" align="center">
<tr>
<td width="19">&nbsp;</td>
<td width="558">
</td>
<td width="17">&nbsp;</td>
</tr>
<tr>
<td width="19">&nbsp;</td>
<td width="558">
<p> Following is a series of questions that will determine if you qualify
for the preliminary part of this study. Please answer all questions by
clicking the cursor in the "Yes" or "No" box adjacent to the question.
When you have answered all the questions click the "Continue" button at
the bottom of the page.
<p align="center"><b>Initial Qualifying Questionnaire</b> <br>
<hr>
</td>
<td width="17">&nbsp;</td>
</tr>
<tr>
<td width="19" height="240">&nbsp;</td>
<td width="558" height="240">
<form id="PreQual1" action="initial-q1.php" method="post" name="PreQual1"><p align="left"><b>
1.) Are you 25 years of age or older?
<br>
<input type="radio" name="age" value="1">Yes
<input type="radio" name="age" value="0">No
</b>
<p><b>
2.) Did your apparitional encounter experience take place
before the age of 13 years old?
<br>
<input type="radio" name="before13" value="1">Yes
<input type="radio" name="before13" value="0">No
</b><p><b>
3.) Were you in a normal waking state going about your
daily activities when you experinced your religious apparitional encounter?
<br>
<input type="radio" name="waking" value="1">Yes
<input type="radio" name="waking" value="0">No
</b><p><b>4.) Were you free of mind altering substances (drugs, alcohol, marijuana, etc.) when you experinced your religious apparitional encounter?<br>
<input type="radio" name="substancefree" value="1">Yes
<input type="radio" name="substancefree" value="0">No
</b>
<p><b>
5.) Was your experience an actual densely present human-like
apparitional encounter with a historical Jewish or Christian religious
figure?
<br>
<input type="radio" name="humanlike" value="1">Yes
<input type="radio" name="humanlike" value="0">No
</b>
<div align="center">
<p><input type="Submit" name="Submit" value="Continue"></p>
</div>
</form></td>
<td width="17" height="240">&nbsp;</td>
</tr>
<tr>
<td width="19">&nbsp;</td>
<td width="558">
<div align="center">
</div>
</td>
<td width="17">&nbsp;</td>
</tr>
<tr>
<td width="19">&nbsp;</td>
<td width="558">&nbsp;</td>
<td width="17">&nbsp;</td>
</tr>
</table>
</body>
</html>Code: Select all
<?php require "db_connect.php"; //this gets the username, host, dbname, password variables to connect to the database
session_start();
//we check to make sure this page was accessed by someone hitting the submit button
if(isset($_POST['Submit'])) {
//need to reset variables to take account of globals being off
$age = $_POST['age'];
$before13 = $_POST['before13'];
$waking = $_POST['waking'];
$substancefree = $_POST['substancefree'];
$humanlike = $_POST['humanlike'];
$date = date('Y-m-d H:i:s');
//set the cookie using the datetime
$_SESSION['qualify'] = $date;
//This is where we connect to the database
$db = mysql_pconnect($db_host, $db_user, $db_pass);
if (!$db) {
//this gives a warning if we can't connect to the database, and then exits
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
//this is the statement that connects to the database table and inserts the new values
//first we do the selecting of the database
//then we define the command with $sql -- telling it to INSERT data into the table fields listed
//and then telling it what data to put in those fields by calling on the POSTed variables from the form
mysql_select_db($db_name, $db);
$sql_qualify = ("INSERT INTO qualify (
age,
before13,
waking,
substancefree,
humanlike,
date)
VALUES (
'$age',
'$before13',
'$waking',
'$substancefree',
'$humanlike',
'$date');");
$result_qualify=mysql_query($sql_qualify,$db) or die("<P>Query failed: ".mysql_error()); //then we tell it to perform the instructions, or give an error message
//then we make sure that all questions were answered Yes - if not then redirect to not qualified page
if($_POST['age'] != 1) {
header('Location: not-qualified.html');
exit();
}
if($_POST['before13'] != 1) {
header('Location: not-qualified.html');
exit();
}
if($_POST['waking'] != 1) {
header('Location: not-qualified.html');
exit();
}
if($_POST['substancefree'] != 1) {
header('Location: not-qualified.html');
exit();
}
if($_POST['humanlike'] != 1) {
header('Location: not-qualified.html');
exit();
}
//Made it through the initial qualifying - redirect to the second part of the prequalification questionnaire
header('Location: initial-q2.html');
exit();
//if this page was reached without hitting the submit button on the form, give an error message
} else {
echo "You did not submit the associated form... you should not be here.";
}
?>Code: Select all
<html>
<head>
<title>Initial Questions-Part 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#333399">
<table width="600" border="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#C5C5EB" align="center">
<tr>
<td width="21">&nbsp;</td>
<td width="556">
<form name="form1" >
<p>&nbsp;</p>
</form>
</td>
<td width="17">&nbsp;</td>
</tr>
<form id="PreQual2" action="initial-q2.php" method="post" name="PreQual2">
<tr>
<td width="21">&nbsp;</td>
<td width="556">
<p><b>6.</b>) <b>Are you currently under psychiatric care?</b> <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Yes
<input type="radio" name="psych" value="1">
No
<input type="radio" name="psych" value="0">
<p><b>7.) Are you currently taking antipsychotic medication? </b> <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Yes
<input type="radio" name="meds" value="1">
No
<input type="radio" name="meds" value="0">
<p><b>8.) Are you pregnant, or have you given birth in the last 6 months?
</b> <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Yes
<input type="radio" name="pregnant" value="1">
No
<input type="radio" name="pregnant" value="0">
<p><b>9.) Have you had surgery or serious illness within the last 6 months?
</b> <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Yes
<input type="radio" name="surgery" value="1">
No
<input type="radio" name="surgery" value="0">
</td>
<td width="17">&nbsp;</td>
</tr>
<tr>
<td width="21">&nbsp;</td>
<td width="556">
<div align="center">
<input type="Submit" name="Submit" value="Continue">
</div>
</td>
<td width="17">&nbsp;</td>
</tr></form>
<tr>
<td width="21">&nbsp;</td>
<td width="556">&nbsp;</td>
<td width="17">&nbsp;</td>
</tr>
<tr>
<td width="21">&nbsp;</td>
<td width="556">&nbsp;</td>
<td width="17">&nbsp;</td>
</tr>
</table>
</body>
</html>Code: Select all
<?php require "db_connect.php"; //this gets the username, host, dbname, password variables to connect to the database
//we check to make sure this page was accessed by someone hitting the submit button
if(isset($_POST['Submit'])) {
//need to reset variables to take account of globals being off
$psych = $_POST['psych'];
$meds = $_POST['meds'];
$pregnant = $_POST['pregnant'];
$surgery = $_POST['surgery'];
//This is where we connect to the database
$db = mysql_pconnect($db_host, $db_user, $db_pass);
if (!$db) {
//this gives a warning if we can't connect to the database, and then exits
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
//this is the statement that connects to the database table and inserts the new values
//first we do the selecting of the database
//then we define the command with $sql -- telling it to INSERT data into the table fields listed
//and then telling it what data to put in those fields by calling on the POSTed variables from the form
mysql_select_db($db_name, $db);
$sql_morequalify = (UPDATE `qualify` SET `psych`=$psych, `meds`=$meds, `pregnant`=$pregnant, `surgery`=$surgery WHERE `date`='".$_SESSION['qualify']."');
$result_morequalify=mysql_query($sql_morequalify,$db) or die("<P>Query failed: ".mysql_error()); //then we tell it to perform the instructions, or give an error message
//then we make sure that all questions were answered Yes - if not then redirect to not qualified page
if($_POST['psych'] != 1) {
header('Location: not-qualified.html');
exit();
}
if($_POST['meds'] != 1) {
header('Location: not-qualified.html');
exit();
}
if($_POST['pregnant'] != 1) {
header('Location: not-qualified.html');
exit();
}
if($_POST['surgery'] != 1) {
header('Location: not-qualified.html');
exit();
}
//Made it through the initial qualifying - redirect to the second part of the prequalification questionnaire
header('Location: cont2consent1.html');
exit();
//if this page was reached without hitting the submit button on the form, give an error message
} else {
echo "You did not submit the associated form... you should not be here.";
}
?>Having said that, the error I'm getting is in the second php script, at the "$sql_morequalify =" line -- a parse error. But I don't know whether that's a problem with the sytax of that line, or the SESSION variable.
Any ideas?
Thanks,
Scott