Hi,
I'm a complete newbie to php (4 weeks) so please excuse my ignorance.
I've created a website in php connected to our access database to service data entry needs (max 4 people). I would now like to add sessions so data entry dosen't get mixed up when submit is pressed by 2 different users accessing the same form.
My question is, is it enough to put my variable into a session as shown below:
$phpVar_P_Title = '';
$phpVar_P_Title = $_SESSION['Title'];
...and then insert the variable into the database table?
Or do I also need to change my sql satements, if statements and html option value php e.g.
if (isset($_SESSION['Title']))
sql = "INSERT INTO tblname (FldTitle) VALUES ('$_SESSION['Title']')";
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="SESSION">
<option value="Mr"<?php if (isset($_SESSION['Title']) && $_SESSION['Title']) == 'Mr') echo "selected"; ?>>Mr</option>
????????
And how do I test that it works in a test (non-live) enviroment where I am the only user?
Any advice or pointers would be much appreciated.
Thanks Knifey
<?php
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')):
header ("Location: indexLOGINPAGE.php");
endif;
$phpVar_P_Title_Mr_status = '';
$phpVar_P_Title_Mrs_status = '';
$phpVar_P_Title = '';
$phpVar_P_Title = $_SESSION['Title'];
if (isset($_POST['Submit_Referral'])):
if (isset($_POST['P_Title'])):
$phpVar_P_Title = check_input($_POST['P_Title']);
if ($phpVar_P_Title == 'Mr'):
$phpVar_P_Title_Mr_status = 'checked';
elseif ($phpVar_P_Title == 'Mrs'):
$phpVar_P_Title_Mrs_status = 'checked'; endif;
else :
$error .= 'Please select a title.\n';
endif;
if($error) :
echo "<script>alert(\"$error\");</script>";
goto endOfScript;
endif;
//add referral to the database
//==========================================
// CONNECT TO THE LOCAL DATABASE and transfer data
//==========================================
sql = "INSERT INTO tblname (FldTitle) VALUES ('$phpVar_P_Title')";
etc.
endif;
endOfScript:
?>
<html>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<br>
<tr>
<td>Title:</td>
<td valign="top" class="td2" >
<select name="P_Title" size="1" >
<option value=""></option>
<option value="Mr"<?php if (isset($_POST['P_Title']) && $phpVar_P_Title == 'Mr') echo "selected"; ?>>Mr</option>
<option value="Mrs"<?php if (isset($_POST['P_Title']) && $phpVar_P_Title == 'Mrs') echo "selected"; ?>>Mrs</option>
</select></td></tr><tr><td colspan="1" align="center">
<input type="submit" name= "Submit_Referral" value="Submit Referral"><input type="reset" value="Reset!"></td>
</tr></form></table></body></html>
I'm a complete newbie to php (4 weeks) so please excuse my ignorance.
I've created a website in php connected to our access database to service data entry needs (max 4 people). I would now like to add sessions so data entry dosen't get mixed up when submit is pressed by 2 different users accessing the same form.
My question is, is it enough to put my variable into a session as shown below:
$phpVar_P_Title = '';
$phpVar_P_Title = $_SESSION['Title'];
...and then insert the variable into the database table?
Or do I also need to change my sql satements, if statements and html option value php e.g.
if (isset($_SESSION['Title']))
sql = "INSERT INTO tblname (FldTitle) VALUES ('$_SESSION['Title']')";
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="SESSION">
<option value="Mr"<?php if (isset($_SESSION['Title']) && $_SESSION['Title']) == 'Mr') echo "selected"; ?>>Mr</option>
????????
And how do I test that it works in a test (non-live) enviroment where I am the only user?
Any advice or pointers would be much appreciated.
Thanks Knifey
<?php
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')):
header ("Location: indexLOGINPAGE.php");
endif;
$phpVar_P_Title_Mr_status = '';
$phpVar_P_Title_Mrs_status = '';
$phpVar_P_Title = '';
$phpVar_P_Title = $_SESSION['Title'];
if (isset($_POST['Submit_Referral'])):
if (isset($_POST['P_Title'])):
$phpVar_P_Title = check_input($_POST['P_Title']);
if ($phpVar_P_Title == 'Mr'):
$phpVar_P_Title_Mr_status = 'checked';
elseif ($phpVar_P_Title == 'Mrs'):
$phpVar_P_Title_Mrs_status = 'checked'; endif;
else :
$error .= 'Please select a title.\n';
endif;
if($error) :
echo "<script>alert(\"$error\");</script>";
goto endOfScript;
endif;
//add referral to the database
//==========================================
// CONNECT TO THE LOCAL DATABASE and transfer data
//==========================================
sql = "INSERT INTO tblname (FldTitle) VALUES ('$phpVar_P_Title')";
etc.
endif;
endOfScript:
?>
<html>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<br>
<tr>
<td>Title:</td>
<td valign="top" class="td2" >
<select name="P_Title" size="1" >
<option value=""></option>
<option value="Mr"<?php if (isset($_POST['P_Title']) && $phpVar_P_Title == 'Mr') echo "selected"; ?>>Mr</option>
<option value="Mrs"<?php if (isset($_POST['P_Title']) && $phpVar_P_Title == 'Mrs') echo "selected"; ?>>Mrs</option>
</select></td></tr><tr><td colspan="1" align="center">
<input type="submit" name= "Submit_Referral" value="Submit Referral"><input type="reset" value="Reset!"></td>
</tr></form></table></body></html>