Hi - I’ve got some php code on this form page - http://www.sturdrinks.eu/uk/free_sample_claim.php but when you enter the details, it brings up an error message saying that the address line 1 field is empty when it’s not. I can’t seem to find anything causing this within the code.
[php]<?php # Script - register.php
// This is the email reg page for the site.
require_once (‘mysqli_connect.php’);
if (isset($_POST[‘submitted’]))
{ // Handle the form.
require_once ('mysqli_connect.php');
// Trim all the incoming data:
$trimmed = array_map('trim', $_POST);
// Assume invalid values:
$t = $fn = $sn = $e = $ad1 = $ci = $pc = FALSE;
// Check for a title:
if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['title']))
{
$t = mysqli_real_escape_string ($dbc, $trimmed['title']);
}
else
{
echo '<p style="font-weight: bold; color: #C00">Please enter your title!</p>';
}
// Check for a first name:
if (preg_match (’/^[A-Z ‘.-]{2,20}$/i’, $trimmed[‘firstname’]))
{
$fn = mysqli_real_escape_string ($dbc, $trimmed[‘firstname’]);
}
else
{
echo ‘
Please enter your first name!
’;}
// Check for a last name:
if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['surname']))
{
$sn = mysqli_real_escape_string ($dbc, $trimmed['surname']);
}
else
{
echo '<p style="font-weight: bold; color: #C00">Please enter your surname!</p>';
}
// Check for an email address:
if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email']))
{
$e = mysqli_real_escape_string ($dbc, $trimmed['email']);
}
else
{
echo '<p style="font-weight: bold; color: #C00">Please enter a valid email address!</p>';
}
// Check for a address line 1:
if (preg_match (’/^[A-Z ‘.-]{2,40}$/i’, $trimmed[‘address1’]))
{
$ad1 = mysqli_real_escape_string ($dbc, $trimmed[‘address1’]);
}
else
{
echo ‘
Please enter Address Line 1!
’;}
// Check for a address line 2, does not need completing:
if (preg_match (’/^[A-Za-z0-9 ‘.-]{2,25}$/i’, $trimmed[‘address2’]))
{
$ad2 = mysqli_real_escape_string ($dbc, $trimmed[‘address2’]);
}
// Check for a City:
if (preg_match (’/^[A-Z ‘.-]{2,40}$/i’, $trimmed[‘town_city’]))
{
$ci = mysqli_real_escape_string ($dbc, $trimmed[‘town_city’]);
}
else
{
echo ‘
Please enter City!
’;}
// Check for postcode:
if (preg_match (’/^[A-Za-z0-9 ‘.-]{2,25}$/i’, $trimmed[‘postcode’]))
{
$pc = mysqli_real_escape_string ($dbc, $trimmed[‘postcode’]);
}
else
{
echo ‘
Please enter Postcode!
’;}
include_once $_SERVER[‘DOCUMENT_ROOT’] . ‘/uk/securimage/securimage.php’;
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == true)
{ // the code was correct
// you should handle the error so that the form processor doesn't continue
$vc = mysqli_real_escape_string ($dbc, $trimmed['captcha_code']);
// or you can use the following code if there is no validation or you do not know how
}
else
{
echo '<p style="font-weight: bold; color: #C00">Please enter the correct text verification!</p>';
}
if ($t && $fn && $sn && $e && $ad1 && $ci && $pc && $vc)
{ // If everything’s OK…
// Make sure the email address is available:
$q = "SELECT id FROM free_sample WHERE email='$e'";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
if (mysqli_num_rows($r) == 0)
{ // email available.
// Create the activation code:
$a = md5(uniqid(rand(), true));
$fl = implode( ',' , $_POST['flavour']);
// Add the user to the database:
$q = "INSERT INTO free_sample (active, reg_date, email, title, firstname, surname, address1, address2, town_city, postcode, flavour) VALUES ('$a', NOW(), '$e', '$t', '$fn', '$sn', '$ad1', '$ad2', '$ci', '$pc', '$fl')";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
if (mysqli_affected_rows($dbc) == 1)
{ // If it ran OK.
[/php]
then the code for the field:
<td class="single-field-left">
<div class="field">
<label for="address1" class="required">
Address Line 1<em class="red">* </em>
</label>
<div class="input-box">
<input name="address1" id="address1" title="address1" value="<?php if (isset($trimmed['address1'])) echo $trimmed['address1']; ?>" class="input-text required-entry"
type="text" />
</div>
</div>
</td>
I’m a bit of a newbie so any help at all is appreciated!