Jump to content

[SOLVED] Parse error


eaglelegend

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/180290-solved-parse-error/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951071
Share on other sites

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' );

?> 

Link to comment
https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951072
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951075
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951077
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/180290-solved-parse-error/#findComment-951079
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.