Can someone check my code?

This is a discussion on Can someone check my code? within the PHP General forums, part of the PHP Programming Forums category; Hello all. I've been trying to figure out what I've done wrong in this code and I think ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-13-2004
junction99
 
Posts: n/a
Default Can someone check my code?

Hello all. I've been trying to figure out what I've done wrong in this
code and I think I've looked at it too long to see what's not working
right. Please help. Thanks to any who are willing to help out.

Here it is:

<?php
$message = '<font color="red">The following errors
occurred:<br><br>';
$problem = FALSE;

# Check for required firstName
if (strlen($_POST['firstName']) > 0){
if (!eregi("^[[:alpha:]-]{2,}$"),
stripslashes(trim($_POST['firstName']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid First Name.</li></ul>';
}
} else {
$problem = TRUE;
$message .= '<ul><li>Please Enter Your First Name.</li></ul>';
}

# Check for required lastName
if (strlen($_POST['lastName']) > 0){
if (!eregi("^[[:alpha:]-]{2,}$"),
stripslashes(trim($_POST['lastName']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid Last Name.</li></ul>';
}
} else {
$problem = TRUE;
$message .= '<ul><li>Please Enter Your Last Name.</li></ul>';
}

# Check for street
if (strlen($_POST['street']) > 0){
if (!eregi("^[[:alnum:][:blank:]-.']{4,}$"),
stripslashes(trim($_POST['street']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid Street
Address.</li></ul>';
}
}

# Check for city
if (strlen($_POST['city']) > 0){
if (!eregi("^[[:alpha:][:blank:]-.']{2,}$"),
stripslashes(trim($_POST['city']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid City.</li></ul>';
}
}

# Check for state
if (strlen($_POST['state']) > 0){
if (!eregi("[AL][AK][AS][AZ][AR][CA][CO][CT][DE][DC][FM][FL][GA][GU][HI][ID][IL][IN][IA][KS][KY][LA][MA][MD][ME][MH][MI][MN][MO][MS][MT][NE][NH][NV][NJ][NM][NY][NC][ND][MP][OH][OK][OR][PW][PA][PR][RI][SC][SD][TN][TX][UT][VT][VI][VA][WA][WV][WI][WY]"),
stripslashes(trim($_POST['state']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid State.</li></ul>';
}
}

# Check for zip
if (strlen($_POST['zip']) > 0){
if (!eregi("^([0-9]{5})(-[0-9]{4})?$"),
stripslashes(trim($_POST['zip']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid Zip.</li></ul>';
}
}

# Check for phone
if (strlen($_POST['phone']) > 0){
if (!eregi("^([0-9]{3})(-[0-9]{3})(-[0-9]{4}$"),
stripslashes(trim($_POST['phone']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid Phone
Number.</li></ul>';
}
}

# Check for required e-mail
if (strlen($_POST['email']) > 0){
if (!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$"),
stripslashes(trim($_POST['email']))){
$problem = TRUE;
$message .= '<ul><li>Please Enter A Valid E-mail
Address.</li></ul>';
} else {
$email = eregi_replace("^[[:alnum:][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$",
'<a href="mailto:\\0">E-mail</a>',
stripslashes(trim($_POST['email'])))){
}
} else {
$problem = TRUE;
$message .= '<ul><li>Please Enter Your E-mail Address.</li></ul>';
}

# Check for required comments
if (strlen($_POST['comments']) > 0){
} else {
$problem = TRUE;
$message .= '<ul><li>Please Enter Your Comments.</li></ul>';
}

if ($_POST['noCom'] > NULL) {
$com = "Checked";
} else $com = "Not Checked";

if (!$problem){
echo "<center><strong>Please check your
information.</strong></center><br><br>";
echo "First Name: <b>($_POST['firstName'])</b><br>";
echo "Last Name: <b>($_POST['lastName'])</b><br><br>";

if (strlen($street) > 0){
echo "Street: <b>$street</b><br>";
}

if (strlen($city]) > 0){
echo "City: <b>$city</b>&nbsp;&nbsp;&nbsp;&nbsp;";
}

if (strlen($state) > 0){
echo "State: <b>$state</b>&nbsp;&nbsp;&nbsp;&nbsp;";
}

if (strlen($zip) > 0){
echo "Zip: <b>$zip</b>";
}
echo "<br><br>";

if (strlen($phone) > 0){
echo "Phone: <b>$phone</b><br><br>";
}

echo "E-mail: <b>($_POST['email'])</b><br>";
echo '"I do not wish to receive communications from
ArrowContracting.com": $com';
echo '<br><br><form
action="http://www.arrowcontracting.com/mail.php"><input type="button"
value="&nbsp;Back&nbsp;"
onClick="history.back()">&nbsp;&nbsp;&nbsp;&nbsp;< input type="submit"
value="&nbsp;Submit&nbsp;"></form>';
} else {
echo $message;
echo '</font><br><br><strong>Please go back and try
again</strong><br><br><br>';
echo '<form><input type="button" value="&nbsp;Back&nbsp;"
onClick="history.back()"></form>';
}

?>


I hope you guys can help me out.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:28 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0