00stuff Posted July 14, 2011 Share Posted July 14, 2011 I'm getting this error and I can't figure out why! Can someone help me please? Error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\Registration\index.php on line 32 My Code: <html> <head> <title>Registration Page</title> <script type="text/javascript"> function validateForm() { var company_name=document.forms["myForm"]["company_name"].value var receive_email=document.forms["myForm"]["receive_email"].value if (company_name==null || company_name=="" || receive_email==null || receive_email=="") { alert("Please fill in all information!"); return false; } } </script> <?php if (isset($_POST['submit'])){ $company_name = $_POST['company_name']; $receive_email = $_POST['receive_email']; $stringData2 = " <?php $name_first = $_POST['name_first']; $name_last = $_POST['name_second']; $phone = $_POST['phone']; $email = $_POST['email']; $message2 = 'First Name: " . $name_first . " \n Last Name: " . $name_last . " \n Phone: " . $phone . " \n Email: " . $email . "'; $to = '" . $receive_email . "'; $subject = 'Registration to " . $company_name . "'; $message = $message2; $from = '" . $receive_email . "'; $headers = 'From:' . $from; mail($to,$subject,$message,$headers); echo 'Mail Sent. Click <a href='register.php'>here</a> to go back!'; ?> "; $ourFileName = "register_ac.php"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fwrite($ourFileHandle, stripslashes($stringData2)); fclose($ourFileHandle); $stringData = " <html> <head> <title>" . $company_name . " Registration</title> <script type='text/javascript'> function validateForm() { var name_first=document.forms['registration_form']['name_first'].value var name_last=document.forms['registration_form']['name_last'].value var phone=document.forms['registration_form']['phone'].value var email=document.forms['registration_form']['email'].value if (name_first==null || name_first=='' || name_last==null || name_last=='' || phone==null || phone=='' || email==null || email=='') { alert('Please fill in all information!'); return false; } } </script> </head> <body> <center> <!-- This is the table that contains the registration form! --> <form name='registration_form' method='post' action='register_ac.php' onsubmit='return validateForm()'> <table bgcolor='#cccccc'> <tr> <td> <table border='0' cellspacing='0' cellpadding='5' width='320'> <tr> <td colspan='2' align='center' bgcolor='white'><h2>" . $company_name . " Registration Page</h2></td> </tr> <tr> <td colspan='2' align='center' bgcolor='white'><font size='2'>All fields are required to submit this form.</font></td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td><b>First Name:</b> </td><td align='right'><input type='text' name='name_first' size='30'></td> </tr> <tr> <td><b>Last Name:</b> </td><td align='right'><input type='text' name='name_last' size='30'></td> </tr> <tr> <td><b>Phone Number:</b> </td><td align='right'><input type='text' name='phone' size='30'></td> </tr> <tr> <td><b>Email:</b> </td><td align='right'><input type='text' name='email' size='30'></td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td> </td><td align='right'><input type='submit' name='submit' value='Register'></td> </tr> </table> </td> </tr> </table> </form> <!-- End of the table containing the Registration form! --> </center> </body> </html>"; $ourFileName = "register.php"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fwrite($ourFileHandle, $stringData); fclose($ourFileHandle); } else { echo " </head> <body> <center> <form name='myForm' method='post' action='' onsubmit='return validateForm()'> <table> <tr> <td colspan='2' align='center'><h2>Registration Configuration Form</h2></td> </tr> <tr> <td>Company Name: </td><td><input type='text' name='company_name' size='30'></td> </tr> <tr> <td>Email: </td><td><input type='text' name='receive_email' size='30'></td> </tr> </table> </form> </center> </body> </html>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241945-parse-error-syntax-error-unexpected-t_encapsed_and_whitespace-expecting-t_str/ Share on other sites More sharing options...
jcbones Posted July 14, 2011 Share Posted July 14, 2011 What are you trying to do, because the code flow just doesn't make any sense. Are you writing the PHP code to stringData2 (1), or do you want PHP to parse the code in stringData2 (2)? Assuming it is (1). ONLY the PHP <?php if (isset($_POST['submit'])){ $company_name = $_POST['company_name']; $receive_email = $_POST['receive_email']; //using a nowdoc, nothing inside this nowdoc will be parsed. $stringData2 = <<<'EOF' <?php $name_first = $_POST['name_first']; $name_last = $_POST['name_second']; $phone = $_POST['phone']; $email = $_POST['email']; $message2 = 'First Name: " . $name_first . " \n Last Name: " . $name_last . " \n Phone: " . $phone . " \n Email: " . $email . "'; $to = '" . $receive_email . "'; $subject = 'Registration to " . $company_name . "'; $message = $message2; $from = '" . $receive_email . "'; $headers = 'From:' . $from; mail($to,$subject,$message,$headers); echo 'Mail Sent. Click <a href='register.php'>here</a> to go back!'; ?> EOF; $ourFileName = "register_ac.php"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fwrite($ourFileHandle, stripslashes($stringData2)); fclose($ourFileHandle); //using a heredoc, variables inside this heredoc will be parsed. $stringData = <<<ROF <html> <head> <title>" . $company_name . " Registration</title> <script type='text/javascript'> function validateForm() { var name_first=document.forms['registration_form']['name_first'].value var name_last=document.forms['registration_form']['name_last'].value var phone=document.forms['registration_form']['phone'].value var email=document.forms['registration_form']['email'].value if (name_first==null || name_first=='' || name_last==null || name_last=='' || phone==null || phone=='' || email==null || email=='') { alert('Please fill in all information!'); return false; } } </script> </head> <body> <center> <!-- This is the table that contains the registration form! --> <form name='registration_form' method='post' action='register_ac.php' onsubmit='return validateForm()'> <table bgcolor='#cccccc'> <tr> <td> <table border='0' cellspacing='0' cellpadding='5' width='320'> <tr> <td colspan='2' align='center' bgcolor='white'><h2>" . $company_name . " Registration Page</h2></td> </tr> <tr> <td colspan='2' align='center' bgcolor='white'><font size='2'>All fields are required to submit this form.</font></td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td><b>First Name:</b> </td><td align='right'><input type='text' name='name_first' size='30'></td> </tr> <tr> <td><b>Last Name:</b> </td><td align='right'><input type='text' name='name_last' size='30'></td> </tr> <tr> <td><b>Phone Number:</b> </td><td align='right'><input type='text' name='phone' size='30'></td> </tr> <tr> <td><b>Email:</b> </td><td align='right'><input type='text' name='email' size='30'></td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td> </td><td align='right'><input type='submit' name='submit' value='Register'></td> </tr> </table> </td> </tr> </table> </form> <!-- End of the table containing the Registration form! --> </center> </body> </html> ROF; $ourFileName = "register.php"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fwrite($ourFileHandle, $stringData); fclose($ourFileHandle); } else { echo " </head> <body> <center> <form name='myForm' method='post' action='' onsubmit='return validateForm()'> <table> <tr> <td colspan='2' align='center'><h2>Registration Configuration Form</h2></td> </tr> <tr> <td>Company Name: </td><td><input type='text' name='company_name' size='30'></td> </tr> <tr> <td>Email: </td><td><input type='text' name='receive_email' size='30'></td> </tr> </table> </form> </center> </body> </html>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241945-parse-error-syntax-error-unexpected-t_encapsed_and_whitespace-expecting-t_str/#findComment-1242549 Share on other sites More sharing options...
00stuff Posted July 14, 2011 Author Share Posted July 14, 2011 I'm getting this error. Parse error: syntax error, unexpected T_SL in /home/content/r/o/c/rochoa1/html/jssamples/register/index.php on line 28 I don't get it on my WAMP server but when I uploaded it to my shared hosting account it gives me this error. Does anyone know why? This is Line 28: $stringData2 = <<<'EOF' Quote Link to comment https://forums.phpfreaks.com/topic/241945-parse-error-syntax-error-unexpected-t_encapsed_and_whitespace-expecting-t_str/#findComment-1242559 Share on other sites More sharing options...
00stuff Posted July 14, 2011 Author Share Posted July 14, 2011 Does anyone kow how this <<<'EOF' works? Do I have to use curly brackets after like this? $variable = <<<'EOF' { } EOF; Quote Link to comment https://forums.phpfreaks.com/topic/241945-parse-error-syntax-error-unexpected-t_encapsed_and_whitespace-expecting-t_str/#findComment-1242670 Share on other sites More sharing options...
jcbones Posted July 14, 2011 Share Posted July 14, 2011 NOPE, but it does depend on PHP 5.3.0 to work. Look for nowdoc. Quote Link to comment https://forums.phpfreaks.com/topic/241945-parse-error-syntax-error-unexpected-t_encapsed_and_whitespace-expecting-t_str/#findComment-1242873 Share on other sites More sharing options...
jcbones Posted July 14, 2011 Share Posted July 14, 2011 To fix your stringData2 without having PHP 5.3.0, then you will have to enclose it in single quotes, and escape EVERY single quote in the string. $stringData2 = ' <?php $name_first = $_POST[\'name_first\']; $name_last = $_POST[\'name_second\']; $phone = $_POST[\'phone\']; $email = $_POST[\'email\']; $message2 = "First Name: $name_first \n Last Name: $name_last \n Phone: $phone \n Email: $email . "; $to = $receive_email; $subject = \'Registration to \' . $company_name; $message = $message2; $from = $receive_email; $headers = \'From:\' . $from; mail($to,$subject,$message,$headers); echo \'Mail Sent. Click <a href="register.php">here</a> to go back!\'; ?> '; Try it and see if that is what you want, as you haven't really stated what you are trying to do. It looks as if you are using PHP to write PHP, so that is the solution I gave you. Quote Link to comment https://forums.phpfreaks.com/topic/241945-parse-error-syntax-error-unexpected-t_encapsed_and_whitespace-expecting-t_str/#findComment-1242878 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.