Hi I used the code
foreach($_POST as $key => $val)
{
if(get_magic_quotes_gpc())
{
$_POST[$key] = stripslashes($val);
}
}
in the initial form, I then tried your later suggestion and placed
//mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query = sprintf("INSERT INTO tenant_details VALUES ('','$last','$first','$male','$dob','$landlordloid','$date')",
mysql_real_escape_string($_POST['surname']),
mysql_real_escape_string($_POST['firstname']),
mysql_real_escape_string($_POST['male_female']),
mysql_real_escape_string($_POST['dob']),
mysql_real_escape_string($_POST['landlordid']),
mysql_real_escape_string($_POST['datesubmitted']));
$result = mysql_query($sql) or die ("Query failed: $sql - " . mysql_error());
Like such. This caused a query failed on every execute no matter what the das was being recovered(ie smith). I took out the latter and just used the first peice of code this again allowed me to to place and also view data. when the data incorporates a ' as in o'reilly the data as stored as such onto the database but i cannot recover and display it. Hope this is clear. I will keep going and jsut hope i dont mess up the code which i have wrote. Many thanks roscor (here is my code).
tenantinput.php.
<? session_start();
if(!session_is_registered('valid_user')){
header("location:../userlogin.php");
}
else
{
}
foreach($_POST as $key => $val)
{
if(get_magic_quotes_gpc())
{
$_POST[$key] = stripslashes($val);
}
}
//echo session_id();
if ((isset($_POST["submit"])) == "send") {
$errcount = 0;
$error1="<span style='color:red'>";
$error2="<span style='color:red'>";
$error3="<span style='color:red'>";
$error4="<span style='color:red'>";
$error15="<span style='color:red'>";
$error16="<span style='color:red'>";
//check if someone has filled out a form
//validate name
if(preg_match('/^[.a-zæøåÆØÅ\S_-]{1,}$/i', $_POST['surname'])){
$last = $_POST['surname'];
}
else {
$error1 .= "You didn't write a Surname!";
$errcount++;
}
if(preg_match('/^[a-zæøåÆØÅ_-]{1,}$/i', $_POST['firstname'])){
$first = $_POST['fisrtname'];
}
else {
$error2 .= "You didn't write a Firstname!";
$errcount++;
}
if(preg_match('/^[a-zæøåÆØÅ_-]{4,}$/i', $_POST['male_female'])){
$male = $_POST['male_female'];
}
else {
$error3 .= "You didn't write Male or Female!";
$errcount++;
}
if (preg_match("/^(0[1-9]|[1-2]{1}[0-9]{1}|3[0-1]{1})-(0[1-9]{1}|1[0-2]{1})-(19[\d]{2}|200[0-5])$/", $_POST['dob'])){
$dob = $_POST['dob'];
}
else {
$error4 .= "You didn't write a Date Of Birth!";
$errcount++;
}
if ($errcount !=0) {
//displays errors in form boxes
}
else {
include("dbinfo.inc.php");
$last= mysql_real_escape_string($_POST['surname']);
$first= mysql_real_escape_string($_POST['fistname']);
$male=$_POST['male_female'];
$dob=$_POST['dob'];
$landlordloid=$_POST['landlordloid'];
$date=$_POST['datesubmitted'];
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tenant_details WHERE surname='$last' and firstname='$first' and male_female='$male' and dob='$dob'";
$result = mysql_query($query);
if(mysql_num_rows($result) == 1){
$last=mysql_result($result,0, 'surname');
$first = mysql_result($result,0, 'firstname');
$male =mysql_result($result,0, 'male_female');
$dob =mysql_result($result,0, 'dob');
$_SESSION['ten_surname']=$last;
$_SESSION['ten_firstname']=$first;
$_SESSION['ten_male_female']=$male;
$_SESSION['ten_dob']=$dob;
echo '<meta http-equiv="refresh" content="0;url=gettd.php">';
} else {
$last=$_POST['surname'];
$first=$_POST['firstname'];
$male=$_POST['male_female'];
$dob=$_POST['dob'];
$landlordloid=$_POST['landlordloid'];
$date=$_POST['datesubmitted'];
$_SESSION['ten_surname']=$last;
$_SESSION['ten_firstname']=$first;
$_SESSION['ten_male_female']=$male;
$_SESSION['ten_dob']=$dob;
echo '<meta http-equiv="refresh" content="0;url=tenantper.php">';
}
}
}
?>
gettd.php
<?
include("dbinfo.inc.php");
$date=$_POST['datesubmitted'];
$last=$_SESSION['ten_surname'];
$first=$_SESSION['ten_firstname'];
$male=$_SESSION['ten_male_female'];
$dob=$_SESSION['ten_dob'];
mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tenant_details WHERE surname='$last' and firstname='$first' and male_female='$male' and dob='$dob'";
$result=mysql_query($query);
$num=stripslashes(mysql_numrows($result));
echo "<b><center>Database Result</center></b><br><br>";
$i=0;
while ($i < $nu) {
$i++;
}
if ($num==0) {
?>
tenantper.php
<? session_start();
if ($_SESSION['posted'] == 1){
echo 'you have already posted data';
exit;
} else {
include("dbinfo.inc.php");
$last=$_POST['surname'];
$first= $_POST['firstname'];
$male=$_POST['male_female'];
$dob=$_POST['dob'];
$landlordloid=$_POST['landlordloid'];
$date=$_POST['datesubmitted'];
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO tenant_details VALUES ('','$last','$first','$male','$dob','$landlordloid','$date')";
mysql_query($query);
echo '<meta http-equiv="refresh" content="0;url=gettd.php">';
// echo "<script>window.location='tenantper.php'</script>";
}
?>