pealo86 Posted April 15, 2010 Share Posted April 15, 2010 Can't get my head around this at all. It works fine when testing locally but won't work on my server! All it is is a basic form script: <?php ####################################################################### // // // // ####################################################################### // send message via email and display results on contact page if (($_POST['contactSend']) || ($_POST['quickSend'])) { // set error variable for each field to use as errorCode // detect whether frm-quick was submitted $error = array (); if ($_POST['quickSend']) { $name = $_POST['quickName']; $email = $_POST['quickEmail']; $emailRep = $_POST['quickEmailRep']; $message = $_POST['quickMessage']; } else { $name = $_POST['contactName']; $email = $_POST['contactEmail']; $emailRep = $_POST['contactEmailRep']; $message = $_POST['contactMessage']; } // email headers $subject = 'Enquiry'; $mailEmail = '[email protected]'; // who will receive the email $mailSender = 'From: ' . $name . '<' . $email . '>'; // who is sending the email // check valid and no null values in fields if (!$name) { $error[] = 'name'; } // check email if ((!preg_match ('#^[^@]+@([a-z0-9\-]+\.)+[a-z]{2,4}$#', $email) || ($email == NULL))) { $error[] = 'email'; } // check email matches only if email is valid if (($errorEmail == 0) && ($email != $emailRep)) { $error[] = 'emailRep'; } // check message exists if (!$message) { $error[] = 'message'; } //default message $errorCount = count ($error); if ($errorCount == 0) { $mailSend = mail ($mailEmail, $subject, $message, $mailSender); // process error if (!$mailSend) { $error[] = 'server'; } else { // mail sent successfully echo ' <div id="frm-pop"> <div>'; echo '<p class="highlight">'; echo "Thankyou for your enquiry. We'll get back to you as soon as possible.</p> </div> </div>"; } } else { // echo error message if unsuccessul // declare warnings $warning = array ('name' => 'You did not enter your name', 'email' => 'You must enter a valid email address', 'emailRep' => 'Your two entered email addresses do not match', 'message' => 'You did not enter a message', 'server' => 'There was a problem processing your message. Please try again'); echo ' <div id="frm-pop"> <div> <p class="highlight">Sorry but there '; switch ($errorCount) { case 1: echo 'was ' . $errorCount . ' error '; break; default: echo 'were ' . $errorCount . ' errors '; } echo ' in your details. Please ' . 'review your entries.</p> <ul class="list bullet">'; foreach ($error as $value) { echo '<li>' . $warning[$value] . '</li>'; } echo '</ul> </div> </div>'; } } ?> The script just cannot seem to put whatever is in the $_POST variables into another variable, such as this line: $name = $_POST['quickName']; If I echo '$name', nothing is output. But if I echo '$_POST['quickName'];' then the value appears on screen! I've double checked to make sure that all of the fields are named correctly in my HTML document also. I even cut out all of the code at the start so that it started with something like: $name = $_POST['quickName']; $email = $_POST['quickEmail']; $emailRep = $_POST['quickEmailRep']; $message = $_POST['quickMessage']; echo $name; No luck again. And even more confusing, I originally added these lines when trying to find the problem: if ($_POST['quickSend']) { $name = $_POST['quickName']; $email = $_POST['quickEmail']; $emailRep = $_POST['quickEmailRep']; $message = $_POST['quickMessage']; echo '1234'; exit; } else { And it brings up this error: Parse error: syntax error, unexpected '}' in /home/inspin/public_html/freshbeat/concept/26032010/script/contact/process.php on line 85 And all that reads on line 85 is this: <p class="highlight">Sorry but there ; !??!?!?!?! Could it be the way my server is configured? As I say, the script works fine locally. What's even more confusing is the way I have very similar scripts running on my same hosting account with none of these issues! Many thanks to anyone who can help. Link to comment https://forums.phpfreaks.com/topic/198636-script-works-locally-but-not-online/ Share on other sites More sharing options...
Pikachu2000 Posted April 15, 2010 Share Posted April 15, 2010 The script looks to be fine. There are no parse errors in it. When you added that block of code to the beginning of the script, did you add the corresponding closing brace for the else{} statement? if not, that is where your error came from. Since the script at least looks fine, can you post the form here? That may be where the problem lies. Link to comment https://forums.phpfreaks.com/topic/198636-script-works-locally-but-not-online/#findComment-1042370 Share on other sites More sharing options...
pealo86 Posted April 15, 2010 Author Share Posted April 15, 2010 Thanks for the help. Yes, I was sure to add the closing brace. I didn't add it to the code snippet in my message purely to save room. Here is the code for my contact form if that helps <form id="frm-contact" name="frm-contact" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <input name="contactSend" type="hidden" id="contactSend" value="1" /> <div> <label>Name</label> <input name="contactName" type="text" id="contactName" size="40" value="<?php if ($errorCount > 0) { if ($_POST['quickSend']) { echo $_POST['quickName']; } else { echo $_POST['contactName']; } } ?>" /> </div> <div> <label>Email Address</label> <input name="contactEmail" type="text" id="contactEmail" size="40" value="<?php if ($errorCount > 0) { if ($_POST['quickSend']) { echo $_POST['quickEmail']; } else { echo $_POST['contactEmail']; } } ?>" /> </div> <div> <label>Repeat Email</label> <input name="contactEmailRep" type="text" id="contactEmailRep" size="40" value="<?php if ($errorCount > 0) { if ($_POST['quickSend']) { echo $_POST['quickEmailRep']; } else { echo $_POST['contactEmailRep']; } } ?>" /> </div> <div> <label>Your Message</label> <textarea name="contactMessage" cols="40" rows="5" id="contactMessage"><?php if ($errorCount > 0) { if ($_POST['quickSend']) { echo $_POST['quickMessage']; } else { echo $_POST['contactMessage']; } } ?></textarea> </div> <div><input type="submit" name="submit" id="submit" class="frm-btn" value="Send Message" /></div> </form> You can see it in action here, notice how it always brings up errors even if you enter valid data into the fields: http://bit.ly/bQpDKQ Link to comment https://forums.phpfreaks.com/topic/198636-script-works-locally-but-not-online/#findComment-1042394 Share on other sites More sharing options...
teamatomic Posted April 15, 2010 Share Posted April 15, 2010 Because you use a hidden input that will always have a value of 1. When you send the form your else will never be used. Get rid of that hidden input and use isset for the submit and go from there. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/198636-script-works-locally-but-not-online/#findComment-1042531 Share on other sites More sharing options...
pealo86 Posted April 15, 2010 Author Share Posted April 15, 2010 I tried removing the if statement all together so that the start of the script contained just this: $name = $_POST['quickName']; $email = $_POST['quickEmail']; $emailRep = $_POST['quickEmailRep']; $message = $_POST['quickMessage']; echo $name; But $name was blank. Then I tried this and it echoed out the value: $name = $_POST['quickName']; $email = $_POST['quickEmail']; $emailRep = $_POST['quickEmailRep']; $message = $_POST['quickMessage']; echo $_POST['quickName']; Perhaps I need to change the error settings so that it displayed everything? Hmmmm Link to comment https://forums.phpfreaks.com/topic/198636-script-works-locally-but-not-online/#findComment-1042551 Share on other sites More sharing options...
TeddyKiller Posted April 15, 2010 Share Posted April 15, 2010 I'm not sure what the problem is exactly. Although.. case 1: should be case "1": Also, you have all the fields for the following.. $name = $_POST['contactName']; $email = $_POST['contactEmail']; $emailRep = $_POST['contactEmailRep']; $message = $_POST['contactMessage']; but not the following. $name = $_POST['quickName']; $email = $_POST['quickEmail']; $emailRep = $_POST['quickEmailRep']; $message = $_POST['quickMessage']; You have stuff to check inside teh form for QUICKs, but the name of the fields are not actually quicks. Not sure if theres anymore form fields that you haven't given, but if not.. then this is your problem. Link to comment https://forums.phpfreaks.com/topic/198636-script-works-locally-but-not-online/#findComment-1042747 Share on other sites More sharing options...
pealo86 Posted April 16, 2010 Author Share Posted April 16, 2010 Thanks but I've ensured that all of the field names match up. I've just tried pasting the code bit by bit into a new file and now it's working! What the?!!? Perhaps the file got corrupted in some way? Link to comment https://forums.phpfreaks.com/topic/198636-script-works-locally-but-not-online/#findComment-1042920 Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 Or perhaps you basically just missed something.. No idea. Glad its working though. Link to comment https://forums.phpfreaks.com/topic/198636-script-works-locally-but-not-online/#findComment-1042970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.