rjcfan4ever Posted July 26, 2011 Share Posted July 26, 2011 I am making a contact script and I put a code into this script where he can read the users login name and e-mail adress and that gives the error. Here is the script: (He gives an syntax error on the last line) <?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { ?> Username:<input type="text" value="<?php echo $_SESSION['Username'];?>" id="username"/><br/> Email: <input type="text" value="<?php echo $_SESSION['EmailAddress'];?>" id="email"/> <?php /* Set e-mail recipient */ $myemail = "[email protected]"; /* Check all form inputs using check_input function */ $yourname = check_input($_POST['yourname'], "Enter your name"); $subject = check_input($_POST['subject'], "Write a subject"); $email = check_input($_POST['email']); $website = check_input($_POST['website']); $likeit = check_input($_POST['likeit']); $how_find = check_input($_POST['how']); $comments = check_input($_POST['comments'], "Write your comments"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* If URL is not valid set $website to empty */ if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website)) { $website = ''; } /* Let's prepare the message for the e-mail */ $message = "Hello! Your contact form has been submitted by: Name: $yourname E-mail: $email URL: $website Like the website? $likeit How did he/she find it? $how_find Comments: $comments End of message "; /* Send the message using mail() function */ mail($myemail, $subject, $message); /* Redirect visitor to the thank you page */ header('Location: thanks.htm'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } ?> Link to comment https://forums.phpfreaks.com/topic/242822-error-in-contact-script/ Share on other sites More sharing options...
Muddy_Funster Posted July 26, 2011 Share Posted July 26, 2011 your function show error at the end is using a variable named $myError - I cant see where, from the code given, that variable is actualy declaired. Also - are you absoloutly certain you want to run exit(); from within the function (not that it's a problem, just something that's worth thinking about)? P.S. - the ACTUAL error message is always appreciated Link to comment https://forums.phpfreaks.com/topic/242822-error-in-contact-script/#findComment-1247174 Share on other sites More sharing options...
ZulfadlyAshBurn Posted July 26, 2011 Share Posted July 26, 2011 didnt i post it on the previous topic? Link to comment https://forums.phpfreaks.com/topic/242822-error-in-contact-script/#findComment-1247178 Share on other sites More sharing options...
ZulfadlyAshBurn Posted July 26, 2011 Share Posted July 26, 2011 you have to edit this part Code: [select] /* Let's prepare the message for the e-mail */ $message = "Hello! Your contact form has been submitted by: Name: $yourname E-mail: $email URL: $website Like the website? $likeit How did he/she find it? $how_find Comments: $comments End of message "; to this Code: [select] /* Let's prepare the message for the e-mail */ $message = "Hello! Your contact form has been submitted by: Name: " . $yourname ." E-mail: " . $email ." URL:" . $website ." Like the website? $likeit How did he/she find it?" . $how_find ." Comments:" . $comments . " End of message Link to comment https://forums.phpfreaks.com/topic/242822-error-in-contact-script/#findComment-1247179 Share on other sites More sharing options...
rjcfan4ever Posted July 26, 2011 Author Share Posted July 26, 2011 I changed in what you said but still the same error with: ?> Link to comment https://forums.phpfreaks.com/topic/242822-error-in-contact-script/#findComment-1247189 Share on other sites More sharing options...
the182guy Posted July 26, 2011 Share Posted July 26, 2011 @Muddy_Funster it's there, look on line ~25 and ~67 @ZulfadlyAshBurn that's not the problem, it is legal syntax to have variables inside a string, as long as it is enclosed by double quotes (which it is). Here are the problems: The syntax error is: unexpected end. This is because you have a missing closing brace } for the first if statement if($_SESSION...). I think you want to add the missing closing brace after the inputs but inside the <?php opening tag. When the above is fixed, the next problem is that you're not initialising the session so you won't have access to $_SESSION. You should call session_start() at the top of the script. The next problem is you have some inputs at the top, but they aren't wrapped in a form. The need a <form> tag with an action set to a processing script. Link to comment https://forums.phpfreaks.com/topic/242822-error-in-contact-script/#findComment-1247190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.