Its been hours, I am trying to add validations like Email, area must not be blank but none have worked for me. Here's the files I am working on
This is Register.php file
<form action="finish.php" method="post"/>
<p>First & Last Name: <input type="text" name="Name"/></p>
<p>Country: <input type="text" name="Country"/></p>
<p>Email Adress <div class="comment">a confirmation email will be sent<br> to you at this address</div><input type="text" name="Email"/></p>
<p>How You Hear About us? <select name="How" id="how" class="how">
<option value="From a Friend">From a Friend</option>
<option value="From Google">From Google</option>
<option value="Advertisements">Advertisments</option>
<option value="Other">Other</option>
</select>
</p>
<input id="submit" type="submit" value="Mail It!" />
</form>
Finish.php File
<?php
define('DB_NAME', 'temp');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not Connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' .DB_NAME . '; ' .mysql_error());
}
$value = $_POST['Name'];
$value2 = $_POST['Country'];
$value3 = $_POST['Email'];
$value4 = $_POST['How'];
$sql ="INSERT INTO tempr (Name, Country, Email, How) VALUES ('$value', '$value2', '$value3', '$value4')";
if (!mysql_query($sql)) {
die('Error: ' .mysql_error());
}
mysql_close();
?>
The form is connected to the Database, so if I add validation it makes it harder to get the data in the database? can anyone please provide me a solution to add validation?
Thanks
FILTER_VALIDATE_EMAILto check for properly formed Email plus you can check if fields are empty by usingif(empty($_POST['Name'])) { die("Enter your name"); }that is a VERY BASIC method. There are many other ways of doing this, by simply Googling "php form validation"ini_set('display_errors',1); error_reporting(E_ALL);to the top of your PHP handler.