Click to See Complete Forum and Search --> : What is wrong?


Jonathan
12-18-2003, 02:35 AM
I can't seem to find what is wrong with this script... I want it to enter it into a database and mail to the pastor. You can see a working one here: crosspoint.org/delete/registration.php but I am not sure if that will help much. Here:


<?php
function connect($db_host,$db_username,$db_password,$db_name){
mysql_pconnect($db_host,$db_username,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
}

function process_registration(){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$ip = $_SERVER['REMOTE_ADDR'];

if(($fname) && ($lname) && ($email) && ($phone) && ($city) && ($state) && ($zip)){
# E-mail
if(!eregi("^[0-9a-zA-Z\.\-\_]+@+[0-9a-zA-Z\.\-\_]+\.+[a-z0-9A-Z\.\_\-]+$", $email)){
echo "Invalid e-mail.";
exit();
}

# Phone number
if(!preg_match("/\d{3}\w?\d{3}\w?\d{4}\w?(\wext\w\d+/i", $phone) || ($phone == "000 000 0000")){
echo "Invalid phone number.";
exit();
}
} else {
echo "Please enter all of the information. (address not included)";
exit();
}

connect("localhost","usr","pass","crosspoint_members");
$selection = mysql_query("select * from registration where ip_address='$ip' or phone_number='$phone' or address='$address' or first_name='$fname' or last_name='$lname' or email_address='$email'") or die(mysql_error());
$number_rows = mysql_num_rows($selection);
if ($number_rows >=1){
echo "Our database contains some/all of the information given. If this is not true, then please contact the webmaster.";
exit();
} else {
$fname = addslashes($fname);
$lname = addslashes($lname);
$email = addslashes($email);
$address = addslashes($address);
$phone = addslashes($phone);
$city = addslashes($city);
$state = addslashes($state);
$zip = addslashes($zip);
$date = date('F d, Y');

$insert = mysql_query("insert into registration values(mysql_insert_id(),$fname,$lname,$email,$address,$phone,$city,$state,$zip,$ip,$date)") or die(mysql_error());

if($insert){
$message = "Registration info below:\n"
."First Name: $fname \n"
."Last Name: $lname \n"
."Email: $email \n"
."Addres: $address \n"
."Phone #: $phone \n"
."City: $city \n"
."State: $state \n"
."Zip Code: $zip \n";
$email = @mail("dvaughan@crosspoint.org","Registration",$message);

if ($email){
echo "E-mail sent to the pastor. Thank you for signing up for Crosspoint Community Church.";
} else {
@mail("webmaster@crosspoint.org","Error (Registration Form)","An error has occured... Please check coding for the registration php page.");
echo "An e-mail was sent to the webmaster because an error has occured in adding information. No private information was sent.";
}
}
?>

I have the process_registration() function on the form. it is a action="<? echo $_SERVER['PHP_SELF']; ?>" ... any help?

Thanks in advance...

pyro
12-18-2003, 08:29 AM
Are you getting any errors? What part is not working?

Jonathan
12-18-2003, 08:43 AM
nothing at all... It just isn't showing up...

YoN
12-18-2003, 08:45 AM
In the code you gave you never call the function, are you calling it from another place in the page? if not, something like this after your function declaration should work fine:if (!empty($_POST["submit"])) {
process_registration();
}

Jonathan
12-18-2003, 11:44 AM
I have done that on another page... I don't know if i called it right... I used this:


<?
if(isset($_POST['submit'])){
process_registration();
}


I am sorry, but I think I said something wrong... I meant to say that the form (with the functino above) was not showing up. I couldn't understand...

EDIT::: Just wondering... Did I forget to add another "}" at the end? Because the else statement... uh... nuts... let me know.

YoN
12-18-2003, 05:13 PM
:oHmmm yeah, you have two '}'s missed.

Jonathan
12-18-2003, 05:52 PM
I got it to work...