Jump to content

How do I solve this PHP code problem?


thuitamaina

Recommended Posts

...
If you visit my website (www.thuitamaina.com) and click the contact link on the menu, a lightbox pop-up form appears. The problems arising are these:
1) The pop-up lightbox that appears after pressing the submit buttton still shows you made a mistake in the contact details even if you filled all the info, put the right email address format and inserted the correct number of bananas in the captcha 
2) The same mistake you made is mentioned several times after clicking submit button
3) If you insert the right details, the "thank you" message is loaded on a different page instead of that same lightbox, and that's after a while.

 

So I ask: 1)how do I make the mistake you made in contact details mentioned only once in the second lightbox? 2)how do I make only the "thank you" message (displayed after you insert correct details) appear in the second lightbox without loading another window?

Please let me know how I can solve those problems. Below is the concerned php code: 

 

 

<?php 
  

$errors 
''
$myemail 'thuitamaina@thuitamaina.com';//<-----Put Your email address here. 
if(empty($_POST['yourname'])  ||  
   empty(
$_POST['email_address']) || 
   empty(
$_POST['Message']) ||  
   empty(
$_POST['captcha'])) 

    
$errors .= "\n Error: all fields are required"
    echo 
'<br>' $errors '<br>'


$yourname $_POST['yourname'];  
$email_address $_POST['email_address'];  
$Message $_POST['Message']; 
$captcha $_POST['captcha'];  

if (!
preg_match
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",  
$email_address)) 

    
$errors .= "\n Error: Invalid email address"
    echo 
'<br>' $errors '<br>'
}   

if ( 
$captcha != 2
 { 
   
$errors .= "\n You inserted the wrong number of <b>FULL</b> bananas. You are not a genuine person!"
   echo 
'<br>' $errors '<br>'
 } 

if( empty(
$errors)) 



// Include database connection settings 
include('clinton.php'); 

$yourname $_POST['yourname'];  
$email_address $_POST['email_address'];  
$Message $_POST['Message'];  

mysql_query("INSERT INTO `thuitam_myDatabase`.`Contact_info` ( 
`Index` , 
`Name` , 
`Email` , 
`Message` 

VALUES ( 
NULL, '
$yourname', '$email_address','$Message') 
"
); 

//close connection                           
mysql_close(); 

$to $myemail

$email_subject "Contact form submission: $yourname"

$email_body "You have received a new message. "

" Here are the details:\n Name: $yourname \n "

"Email: $email_address\n Message \n $Message"

$headers "From: $myemail\n"

$headers .= "Reply-To: $email_address"

mail($to,$email_subject,$email_body,$headers); 

//Say 'thank you' 
//echo '<br>' . $errors . '<br>'; 

echo '<p>Hi ' $yourname '!</p> 

<p>Thank you for contacting me. I will try my best to get back to you as soon as possible. In case I delay in responding, feel free to call me via phone. My number is +254725-509941.</p> 

<p>Wishing You Every Joy,</p> 

<p>Thuita J. Maina.</> 
'


 

Link to comment
Share on other sites

Your post begins with what looks like a conversation you are having with someone else. What are you trying to say to US?

 

Your code is weak. You are collecting error messages but outputting them individually so if you have multiple errors you will see the messages multiple times. Either save the output of the errors until the end or do an exit once you do output a message.

 

Your query looks like it has an error in it with that period in the middle of it.

 

I don't know what else you have a problem with.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.