Dear
I am beginner of PHP programming I tried my best to run below given code but failed. Please solve it.
Regards,
Mumtaz Ali
I am beginner of PHP programming I tried my best to run below given code but failed. Please solve it.
Code:
<html>
<head><title>Form</title></head>
<body>
<h1>Web Developer Required</h1>
<h4>Please fill the following form to apply for this job</h4>
<form method= "post" action = "application.php">
<table width "100%" border="1">
<tr><td>Name: </td><td><input type="text" name= "name" /></td></tr>
<tr><td>Phone: </td><td><input type="text" name= "phone" /></td></tr>
<tr><td>Email: </td><td><input type="text" name= "email" /></td></tr>
<tr><td>Address: </td><td><input type="text" name= "address" /></td></tr>
<tr><td>Gender: </td><td><input type="text" name= "gender" type="radio" value= "male" />
Female:<input name="gender" type= "radio" value="female" /></td></tr>
<tr><td>City: </td><td><select name ="city">
<option>Islamabad</option>
<option>Karachi</option>
<option>Lahore</option>
<option>Quetta</option>
</select></td></tr><tr>
<tr><td>Age: </td><td><input ="text" name="age" /></td></tr>
<tr><td=width="40%" valign="top"> Skills </td><td>
PHP: <input type= "checkbox"name="skills[]" value "PHP"><br>
HTML: <input type= "checkbox"name="skills[]" value "HTML>"<br>
Photoshop: <input type= "checkbox"name="skills[]" value "Photoshop>"<br>
Javascript: <input type= "checkbox"name="skills[]" value "Javascript />"<br/>
Ajax: <input type= "checkbox"name="skills[]" value "Ajax"/> <br/>
MySQL: <input type= "checkbox"name="skills[]" value "MySQL" />
</td></tr><tr><td valigen="top"> </td>
<td><input type="submit" name= "submit" value= "Submit" />
<input type="reset" name= "submit2" value= "Reset" /></td>
</tr></table></bpdy></html>
<?php
function cleanStr($str) {
$cStr = trim($str);
$cStr = htmlspecialchars($str);
$cStr = addslashes($str);
return $cStr;
}
function emptyFields($ar){
if(!is_array($ar)) {
print "The argument must be an array";
return false;
}
foreach($ar as $key => $value) {
$value = celanStr($value);
if(empty($value)) {
print "<b>" . ucwords($key) . "</b>
must not be empty. Please Click browser
back button and correct it.";
return false;
}
}
return true;
}
if(!emptyFields($_POST)) {
exit();
}
//check required skills and age
function isEligible($skills, $age){
$age = intval($age);
if(count($skills) == 0){
print ("You dont have any skills");
return false;
}
if($age < 23 || $age > 35) {
print("Your age must be between 23 and 35");
return false;
}
return true;
}
// assigning fields value to variable
$name= cleanStr($_POST['name']);
$phone= cleanStr($_POST['phone']);
$email= cleanStr($_POST['email']);
$address= cleanStr($_POST['address']);
$gender= $_POST['gender'];
$city = $_POST['city'];
$age = (int)cleanStr($_POST['age']);
$skills = $_POST['skills'];
//call func candidate is eligible
if (!isEligible($skills,$age)) {
exit();
}
// if every thing is ok
print "<h4>Thanks your ". $name.
"for your interest in this job. We will contact you soon. </h4>";
print "We received the following information about you. <br>";
//printing user submitted information
print "Name: " . $name . "<br>";
print "Phone: " . $phone . "<br>";
print "Email: " . $email . "<br>";
print "Address: " . $address . "<br>";
print "Gender: " . $gender . "<br>";
print "City: " . $city . "<br>";
print "Age: " . $age . "<br>";
print "Your Skills :" ;
foreach($skills as $value)
{
print $value . ",";
}
?>
Regards,
Mumtaz Ali
Comment