eaglelegend Posted November 4, 2009 Share Posted November 4, 2009 Hi, sorry guys, I have come accross an error on my site and I am unsure qhats causing it, this is the error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in contact.php on line 44 This is everything from line 1 to 50; <?php session_name("fancyform"); session_start(); $_SESSION['n1'] = rand(1,20); $_SESSION['n2'] = rand(1,20); $_SESSION['expect'] = $_SESSION['n1']+$_SESSION['n2']; $str=''; if($_SESSION['errStr']) { $str='<div class="error">'.$_SESSION['errStr'].'</div>'; unset($_SESSION['errStr']); } $success=''; if($_SESSION['sent']) { $success='<h1>Thank you!</h1>'; $css='<style type="text/css">#contact-form{display:none;}</style>'; unset($_SESSION['sent']); } $page = 'contact'; $content=<<<EOF <div id="main-container"> <div id="form-container"> <h1>Contact Form</h1> <h2>Why not drop us a line and we will get back to you!</h2> <form id="contact-form" name="contact-form" method="post" action="submit.php"> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="15%"><label for="name">Name</label></td> <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td> <td width="15%" id="errOffset"> </td> </tr> <tr> <td><label for="email">Email</label></td> <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td> <td> </td> Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/ Share on other sites More sharing options...
Adam Posted November 4, 2009 Share Posted November 4, 2009 Most likely you have short_open_tag disabled and so the short-hand syntax doesn't work. Try changing it to the standard: <?php echo $_SESSION['post']['name']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951055 Share on other sites More sharing options...
eaglelegend Posted November 4, 2009 Author Share Posted November 4, 2009 Thanks, but still not working :/ :'( any Ideas? Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951067 Share on other sites More sharing options...
Adam Posted November 4, 2009 Share Posted November 4, 2009 Is it the same error, or from another line? Just spotted similar syntax 5 lines down. Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951069 Share on other sites More sharing options...
simshaun Posted November 4, 2009 Share Posted November 4, 2009 Try this: <?php session_name("fancyform"); session_start(); $_SESSION['n1'] = rand(1,20); $_SESSION['n2'] = rand(1,20); $_SESSION['expect'] = $_SESSION['n1']+$_SESSION['n2']; $str=''; if($_SESSION['errStr']) { $str='<div class="error">'.$_SESSION['errStr'].'</div>'; unset($_SESSION['errStr']); } $success=''; if($_SESSION['sent']) { $success='<h1>Thank you!</h1>'; $css='<style type="text/css">#contact-form{display:none;}</style>'; unset($_SESSION['sent']); } $page = 'contact'; $content=<<<EOF <div id="main-container"> <div id="form-container"> <h1>Contact Form</h1> <h2>Why not drop us a line and we will get back to you!</h2> <form id="contact-form" name="contact-form" method="post" action="submit.php"> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="15%"><label for="name">Name</label></td> <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="{$_SESSION['post']['name']}" /></td> <td width="15%" id="errOffset"> </td> </tr> <tr> <td><label for="email">Email</label></td> <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="{$_SESSION['post']['email']}" /></td> <td> </td> EOF; // There must be a hard-return afer EOF; or you will receive an end-of-file error. Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951071 Share on other sites More sharing options...
eaglelegend Posted November 4, 2009 Author Share Posted November 4, 2009 Same error, I tried changing the other one you mentioned but same error, so heres the full code, I dont believe it is over 300 lines though. <?php session_name("fancyform"); session_start(); $_SESSION['n1'] = rand(1,20); $_SESSION['n2'] = rand(1,20); $_SESSION['expect'] = $_SESSION['n1']+$_SESSION['n2']; $str=''; if($_SESSION['errStr']) { $str='<div class="error">'.$_SESSION['errStr'].'</div>'; unset($_SESSION['errStr']); } $success=''; if($_SESSION['sent']) { $success='<h1>Thank you!</h1>'; $css='<style type="text/css">#contact-form{display:none;}</style>'; unset($_SESSION['sent']); } $page = 'contact'; $content=<<<EOF <div id="main-container"> <div id="form-container"> <h1>Contact Form</h1> <h2>Why not drop us a line and we will get back to you!</h2> <form id="contact-form" name="contact-form" method="post" action="submit.php"> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="15%"><label for="name">Name</label></td> <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?php echo $_SESSION['post']['name']; ?>" /></td> <td width="15%" id="errOffset"> </td> </tr> <tr> <td><label for="email">Email</label></td> <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td> <td> </td> </tr> <tr> <td><label for="subject">Subject</label></td> <td><select name="subject" id="subject"> <option value="" selected="selected"> - Choose -</option> <option value="Question">Question</option> <option value="Business proposal">Business proposal</option> <option value="Advertisement">Advertising</option> <option value="Complaint">Complaint</option> </select> </td> <td> </td> </tr> <tr> <td valign="top"><label for="message">Message</label></td> <td><textarea name="message" id="message" class="validate[required]" cols="35" rows="5"><?=$_SESSION['post']['message']?></textarea></td> <td valign="top"> </td> </tr> <tr> <td><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td> <td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td> <td valign="top"> </td> </tr> <tr> <td valign="top"> </td> <td colspan="2"><input type="submit" name="button" id="button" value="Submit" /> <input type="reset" name="button2" id="button2" value="Reset" /> <?=$str?> <img id="loading" src="/img/ajax-load.gif" width="16" height="16" alt="loading" /></td> </tr> </table> </form> <?=$success?> </div> </div> <br /> <br /> EOF; include_once ( 'template.php' ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951072 Share on other sites More sharing options...
simshaun Posted November 4, 2009 Share Posted November 4, 2009 Take a look at where everything turns black in the code you just posted and you will see the error. (see my post above) Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951073 Share on other sites More sharing options...
eaglelegend Posted November 4, 2009 Author Share Posted November 4, 2009 Simshaun, I pasted this code where i copied the "sample" code earlier, into the full code, and the error changed to; Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in contact.php on line 65 Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951075 Share on other sites More sharing options...
simshaun Posted November 4, 2009 Share Posted November 4, 2009 You copied and pasted my sample code? Im a bit confused as to what you've done, but you did not copy/paste what I posted. Take a look specifically at the parts where you close PHP in the middle of your HTML: <?php echo $_SESSION['post']['name']; ?> <?=$_SESSION['post']['email']?> <?=$_SESSION['post']['message']?> <?=$_SESSION['n1']?> <?=$_SESSION['n2']?> <?=$success?> (and possibly more; I only skimmed through the last code you posted.) You can not close PHP in the middle of your heredoc syntax as you are doing. See my code from the previous post for the correct way. Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951077 Share on other sites More sharing options...
nadeemshafi9 Posted November 4, 2009 Share Posted November 4, 2009 try $name = $_SESSION['post']['name']; $content=<<<EOF <div id="main-container"> <div id="form-container"> <h1>Contact Form</h1> <h2>Why not drop us a line and we will get back to you!</h2> <form id="contact-form" name="contact-form" method="post" action="submit.php"> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="15%"><label for="name">Name</label></td> <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="$name" /></td> OR <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="{$name}" /></td> <td width="15%" id="errOffset"> </td> </tr> <tr> <td><label for="email">Email</label></td> <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td> <td> </td> Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951079 Share on other sites More sharing options...
eaglelegend Posted November 4, 2009 Author Share Posted November 4, 2009 Thanks simshaun - I reread your first post and worked it out for myself, for the rest of the code I mean, it is now working thanks to you! Quote Link to comment https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951094 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.