Jump to content

How, if possible, could I implement cookies and sessions into a code like this?


APD1993

Recommended Posts

I have two files with coding in. One of them is the HTML form file:

 

<?php
<html><head><title>Car Accident Program</title></head>
<body>
<!----In this block of code I am creating a form with 4 text boxes and a button as well as user prompts to get user inputted values to work with---->
<h4>Car Accident Report Form</h4>
<form action="Car.php" method="post">
<b>First Name:<b><br>
<input type="text" size = "45" name="firstname"><br>
<b>Surname:<b><br>
<input type="text" size = "45" name="surname"><br>
<b>Age:<b><br>
<input type="text" size = "45" name="age"><br>
<b>Number of weeks since accident:<b><br>
<input type="text" size = "45" name="weeks"><br>
<input type="submit" value="Submit report">
</form>
</body>
</html>

 

and the PHP/Validation file:

 

<!----In this block of code, I am creating a PHP script that gets the user inputted values and can display them in a report as well as use an IF statement to show an extra line to appear if the user enters an age below 18 or a time since accident below 1 week or if they miss out a field or more---->
<?php

$firstname= $_POST ['firstname'];
$surname =$_POST ['surname'];
$age=$_POST ['age'];
$weeks=$_POST ['weeks'];

//Here, I am providing various paths and the outcomes in a PHP script

if (empty($_POST['firstname']) or empty($_POST['surname']) or empty($_POST['age']) or empty($_POST['weeks']))
{$msg= "You missed out one or more fields. Click on the link below to go back to the form and enter information into all of the fields";}
else if (is_numeric($age) && $age<0)
{$msg="You cannot be under 0 years of age";}
else if (is_numeric($weeks) && $weeks<0)
{$msg="The number of weeks since an accident cannot be below 0";}
else if (is_numeric($age) && $age>0 && $age<18)
{$msg= "You are too young to file an accident report";}

else if (is_numeric($weeks) && $weeks<2)
{$msg= "You cannot file an accident report that happened less than two weeks ago";}
else
{
setcookie("
$msg= "First Name: $firstname<br>";
$msg .="Surname: $surname<br>";
$msg .= "Age: $age<br>";
$msg .="Number of weeks since accident: $weeks<br>";
$msg .="Your report has been accepted. Please click on the link below to go back to the Accident Report Page";}
echo ($msg)
?>


</body>
</html>
<html>
<a href="http://localhost/Car.htm"><br><br>Click here to add/edit an Accident Report</a>

 

I was wondering how, if suitable, I would add a cookie or session into coding like this.

 

Any help is appreciated,

 

Andrew :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.