I was experimenting with this again and I can't get it to post any of the information to the database. I have it posting back to the same page and when I hit "Submit" it shows the page minus the forum. I don't have a problem there, from what I know.
However, the information isn't being recorded into the database. I modified the code a bit since I last posted so I'm posting it again. I'll keep playing with it and if I get it to work I'll report back.
The index.php file:
php Code:
<?php
include('../includes/constants.php');
include('../includes/sanitize.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Coming Soon!</title>
</head>
<body>
We are trying to get things running, please pardon the
virtual dust!
<p>If you would like us to notify you when we get setup fill out the form below with your name and email address.</p>
<?php
if (isset($_POST&
#91;'submitted'])) {
//Sanitize data before validation
$c_fname = sanitize(3, 15, $_POST['first_name']);
$c_lname = sanitize(3, 25, $_POST['last_name']);
$c_email = sanitize(5, 60, $_POST['email']);
$c_email_2 = sanitize(5, 60, $_POST['email_2']);
//Validate the first name
[a-zA-Z]
[a-zA-Z.-]{1,15}/", $c_fname);
//Validate last name
[a-zA-Z]
[a-zA-Z-]{1,25}/", $c_lname);
//Is the email valid and not empty?
echo '<p>Please enter your email address in both fields.</p>';
} else if ($c_email != $c_email_2) {
echo '<p>The email fields do not match. Please confirm them again.</p>';
} else {
function isValidEmail( $c_email = null ) {
[\d\w\/+!=#|$?%{^&}*`'~-]
[\d\w\/\.+!=#|$?%{^&}*`'~-]*@
[A-Z0-9]
[A-Z0-9.-]{1,60}
[A-Z0-9]\.
[A-Z]{2,6}/", $c_email);
}
}
if (!
empty($c_email) &&
$c_email ==
$c_email_2) { $access = "SELECT Email FROM customers WHERE Email='$c_email'";
$r = mysqli_query
($dbc,
$access) or
trigger_error("Query: $access\n<br />MySQL error: " . mysqli_error
($dbc));
}
//Insert information if email is unique:
if (mysqli_num_rows($r) == 0) {
$access = "INSERT INTO customers (email, first, last) VALUES ('$c_email', '$c_fname', '$c_lname')";
$r = mysqli_query
($dbc,
$access) or
trigger_error("Query: $access\n<br />MySQL error: " . mysqli_error
($dbc));
} else {
echo '<p>Your email address could not be recorded due to an error, please try again.</p>';
}
mysqli_close($dbc);
} // End Submit IF.
?>
<form action="index.php" method="post">
<fieldset>
<p><b>First name:</b> <input type="text" name="first_name" size="20" maxlength="15" value="<?php if(isset($c_fname)) echo $c_fname; ?>" /></p>
<p><b>Last name:</b> <input type="text" name="last_name" size="20" maxlength="25" value="<?php if(isset($c_lname)) echo $c_lname; ?>" /></p>
<p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="60" value="<?php if(isset($c_email)) echo $c_email; ?>" /> (Required)</p>
<p><b>Confirm email address:</b> <input type="text" name="email_2" size="30" maxlength="60" value="<?php if(isset($c_email_2)) echo $c_email_2; ?>" /> (Required)</p>
<br />
</fieldset>
<div class="center"><input type="submit" name="submit" value="Register" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>
Constants.php:
php Code:
<?php
define('BASE_URL',
'http://mysite.com');
define('MYSQL',
'../SQL/mysqli_connect.php');
?>
php Code:
<?php
//Set database access information:
DEFINE('DB_USER',
'********');
DEFINE('DB_PASSWORD',
'********');
//Attempt to connect to MySQL
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$dbc) {
trigger_error('Could not connect to MySQL: ' . mysqli_connect_error
() );
}
?>