Here's my Code:
Code: Select all
if(isset($_POST['submit'])) {
$output_form = false;
$email=$_POST['email'];
$name=$_POST['name'];
$phone=$_POST['cell'];
$zip=$_POST['zip'];
if(empty($name) && empty($email) && empty($phone) && empty($zip)) {
echo 'All fields are blank. <br />';
$output_form = true;
}
if(empty($name)) && (!empty($email)) && (!empty($phone)) && (!empty($zip))) {
echo 'Name field was left blank. <br />';
$output_form = true;
}
//CONTINUE CHECKING FOR EMPTY VARIABLES
...
if((!empty($name) && (!empty($email)) && (!empty($phone)) && (!empty($zip))) {
require("databasecon.php");
$query = "INSERT INTO data_base (email, name, cell, zip)" . "VALUES ('$email', '$name', '$phone', '$zip')";
mysqli_query($dbc, $query)
or die('Error. Connection could not be established.');
require("confirmation.php");
}
}
else{
$output_form = true;
}
if($output_form) {
?>
<form method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>"?
Name: <input id="name" type="text" size="25" maxlength="25" class="formfield" value="<?php echo $name; ?>"/><br />
E-mail: <input id="email" type="text" size="30" maxlength="30" class="formfield" value="<?php echo $email; ?>"<br />
Cell: <input id="cell" type="text" size="10" maxlength="10" class="formfield" value="<?php echo $cell; ?>"<br />
Zip Code: <input id="zip" type="text" size="5" maxlength="5" class="formeidl" value="<?php echo $zip; ?>"<br />
<input type="submit" name="submit" id="submit" value="Process" />
<?php
}
?>
I realize this may not be the best way to do this. I also think the issue is with the && operator because it will tell me that all fields are empty regardless of whether or not they have anything in them. I also have an issue with making the data the user enters "sticky".
Help!