PHP Code Help please. thanks.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mohamedselim
Forum Newbie
Posts: 1
Joined: Tue Mar 15, 2011 8:16 am

PHP Code Help please. thanks.

Post by mohamedselim »

i have a PHP code for a customer comments and its working fine
its about a customer add a comments and it sends to my email..
well when i test it if the customer leave any blank field it still send the email , but in the same time get a page for a customer that the field is empty and need to go back.
and when all field is done it redirect to a thank you page. thats whats working now

I need to add on this php code , that when the customer leaves any field empty , redirect to an error page ( which i already created ) and when the customer enters any invalid email also redirect to an error page , and when all field is done and the customer press submit , automatically send an email to the customer with my name and my email to tell them that we will contact you asap.

the error page i created called : error_message,htm

Please help me in that im not a php coder pro. thanks

here is the the code i have

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Customer Comments';

// Your email address. This is where the form information will be sent.
$emailadd = 'email@.com';

// Where to redirect after form is processed.
$url = 'http://mythankyoupage';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '1';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

thanks all appreciate any help really , thanks again.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Code Help please. thanks.

Post by AbraCadaver »

Unfortunately it clearly states:

// --------------------------Do not edit below this line--------------------------
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: PHP Code Help please. thanks.

Post by akuji36 »

Hello

You are looking for php isset function which checks if the form fields have a value.

Take a look at the following link and try to write your own code.

http://snipplr.com/view/11093/use-of-ph ... bmit-form/
Post Reply