Chaps, as a beginner developing his first web app in PHP, I have done fairly well.
However, I am struggling when it comes to validation.
I have written different ELSEIF statements as seen below which would actually carry out the validation itself.
// First name must be filled and in correct format.
if(empty($FirstName)) {
$errFirstName = '<p class="errText"> Please enter a value</p>';
echo $errFirstName;
}elseif(!preg_match('/^[a-z]+$/i',$FirstName)){
$errFirstName = '<p class="errText">Name may not start with a dash. Letters, spaces and dashes are accepted.</p>';
echo $errFirstName;
}
The problem is that I do not know how to make them "pop up" when the user makes a mistake.
I have a form in addteam.php seen below:
<form action="pushteam.php" method="post">
<p>Team name: <input type="text" name="TeamName" /></p>
<p>Description: </p>
<p><textarea name="Description" rows="4" cols="50">Add your description here.</textarea></p>
<p><input type="submit"/></p>
</form>
And a pushplayer.php script that pushes it to a mysql database:
// Get values from form
$TeamName=$_POST['TeamName'];
$Description=$_POST['Description'];
}
// Insert data into database
$sql="INSERT INTO Teams(TeamName, Description)VALUES('$TeamName', '$Description')";
$result=mysql_query($sql);
//If successful return to success.php else print error
if($result){
header( 'Location: success.php');
}
else {
header( 'Location: failure.php');
}
The scripts function properly. I would really appreciate if someone could guide me in the right direction here. Make the error pop up and make sure the data is not input. At the moment, if I add my ELSEIF statements, it will carry on and insert the data anyway and redirect me. Thanks