?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

?
?PHP Database integration... need help
Author:??(---.computing.dcu.ie)
Date:???05-01-04 03:40

Hi there, I'm doing a college project with a website. I'm having trouble trying to get user information from a form and add it to the database and at the same time I want to send out a confirmation e-mail to teh customer but keep getting errors from my server. The first line is ok, thats for my server to parse php.

#!/usr/local/bin/php


if($Submit)
{
$link = mysql_connect("mysql.internal", "baz", "rREfp2t4");
if ( ! $link )
die( "Couldn't connect to Database" );
$db = baz;
mysql_select_db( $db ) or die ( "Couldn't open $db: ".mysql_error() );

// if customers details have been entered
$check = True;
$done = False;
// confirm all details entered
if ($_POST["fname"] =="" or $_POST["lname"]=="" or $_POST["Address1"]=="" or $_POST["Address2"]=="" or $_POST["Address3"]=="" or $_POST["Address4"]=="" or
$_POST["phoneNum"]=="" or $_POST["mobNum"]=="" or $_POST["email"]=="")
{
echo '
One or more of the fields were left blank. Please fill them as we need all of the details in order to send out an engineer.
';
echo '
TRY AGAIN!
';
$check = False;
exit;
}

//These are functions to ensure that correct details have been entered into each field
if($_POST["fname"] != "")
{
if (eregi("[[:alpha:]]", $_POST["fname"]))
{
$check = True;
}
else
{
echo '
You appear to have entered the details in the First Name field incorrectly. Please try again
';
echo '
TRY AGAIN!
';
$check = False;
exit;
}
}
if($_POST["lname"] != "")
{
if (eregi("[[:alpha:]]", $_POST["lname"]))
{
$check = True;
}
else
{
echo '
You appear to have entered the details in the Last Name field incorrectly. Please try again
';
echo '
TRY AGAIN!
';
$check = False;
exit;
}
}
if($_POST["Address1"] != "")
{
if (eregi("[[:alnum:]]", $_POST["Address1"]))
{
$check = True;
}
else
{
echo '
You have entered and invalid Address Line 1. Please re-enter these details
';
echo '
TRY AGAIN!
';
$check = False;
exit;
}
}
if($_POST["Address2"] != "")
{
if (eregi("[[:alnum:]]", $_POST["Address2"]))
{
$check = True;
}
else
{
echo '
You have entered and invalid Address line 2. Please re-enter these details
';
echo '
TRY AGAIN!
';
$check = False;
exit;
}
}
if($_POST["Address3"] != "")
{
if (eregi("[[:alnum:]]", $_POST["Address3"]))
{
$check = True;
}
else
{
echo '
You have entered and invalid Town Address. Please try again
';
echo '
TRY AGAIN!
';
$check = False;
exit;
}
}
if($_POST["phoneNum"] != "")
{
if (eregi("[[:digit:]]", $_POST["phoneNum"]))
{
$check = True;
}
else
{
echo '
You have entered and invalid Phone Number. Please try again
';
echo '
TRY AGAIN!
';
$check = False;
exit;
}
}
if($_POST["mobNum"] != "")
{
if (eregi("[[:digit:]]", $_POST["mobNum"]))
{
$check = True;
}
else
{
echo '
You have entered and invalid Phone Number. Please enter the full international number. For example, for the number +353 (0)87 1234567, enter 353871234567. Please try again
';
echo '
TRY AGAIN!
';
$check = False;
exit;
}
}
if($_POST["email"] != "")
{
if (eregi("^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,6}$", $_POST["email"]))
{
$check = True;
}
else
{
echo '
You have entered and invalid email address. Please try again
';
echo '
TRY AGAIN!
';
$check = False;
exit;
}
}


// if true store Customers details in DB
if($check == True)
{
$sql = "INSERT INTO Customers SET f_name = '$_POST["fname"]', l_name = '$_POST["lname"]', addr1 = '$_POST["Address1"]',
addr2 = '$_POST["Address2"]', addr3 = '$_POST["Address3"]', addr4 = 'Dublin $_POST["Address4"]', ph_Num = '$_POST["phoneNum"]', mob_Num = '$_POST["mobNum"]', email = '$_POST["email"]', ";
$result=mysql_query($sql);
if(!$result)
{
echo "
A database error occured in processing your submission.\nIf this error persists, please email Administration
" . mysql_error();
echo "Home
";
}
else
{
echo '
Thank you! We will be in contact to make an appointment within 24 hours!
';
//Email the receipt to the customer.

$custMessage="Thank you $_POST["fname"] we will be in contact about a callout to:
$_POST["Address1"]
$_POST["Address2"]
$_POST["Address3"]
$_POST["Address4"]";

$staffMessage="Customer Looking for callout ASAP to:
$_POST["fname"] $_POST["lname"]
$_POST["Address1"]
$_POST["Address2"]
$_POST["Address3"]
$_POST["Address4"]
$_POST["phoneNum"]
$_POST["mobNum"]
$_POST["email"]";

if(mail("$_POST["mobNum"]@pswin.com","ABC HEATING","$custMessage","From:ABC HEATING:") && mail("[email protected]","Customer Booking","$staffMessage","From:Website:"))
{
echo '
' . 'Your Booking has been received. An SMS has been sent to you with confirmation!' .'

';
echo("
Home
");
}
else
{
echo '
Mail could not be sent.
';
exit;
}
$done= True;
}
}
}

?>

?Re: PHP Database integration... need help
Author:?Barry?(---.bas2.prp.dublin.eircom.net)
Date:???05-02-04 09:12

Figured it out, was simply that my sql server needed me to concatonaate the strings being entered into the database with the "." operator to stop the server confusing all of the " operators with each other...

Go to Top??|??Go to Topic??|??Threaded View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??

Provided By
Phorum