• Resolved Leinad4Mind

    (@leinad4mind)


    I’m getting this:
    Parse error: syntax error, unexpected '<', expecting end of file in /wp-content/plugins/post-snippets/src/PostSnippets/Shortcode.php(105) : eval()'d code on line 1

    I’ve this code:

    <?php
    	if (isset($_POST['real'])){
    		$real=$_POST['real']; //Get the global variable of the first number
    		$height=$_POST['height']; //Get the global variable of the second number
    		if ($real!=null or $height!=null){ //I continue if at least one number is defined
    			if ($real==null){ $real=0; } //If the first number is null, I associate it with zero
    			if ($height==null){ $height=0; } //If the second number is null, I associate it with zero
    			$total=$real*$height/170; //High numbers and define $total (result)
    			$total=round($total,2);
    		}
    	}
    	else{
    	$real=0;
    	$height=0;
    	$total=0;
    	}
    ?>
    <form action="<?php htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST" style="padding-top:0px">
    <table border="1" bordercolor="#000000" style="max-width:500px;">
    <tr>
    <td width="20%" bgcolor="#dddddd"><span class="Stile1"><b>Come calcolare le Proporzioni?</b><br/>
      </span>
      <p class="Stile1">Inserire nella casella &quot;Dimensione real&quot;</p>
      <div align="center"><b><span class="Stile1">1. Dimensione real:</span>&nbsp;</b><input type="text" name="real" size="10" value="<?php htmlspecialchars($real);?>"></div><br/><br/>
    <p class="Stile1">Inserire l'height</p><div align="center"><span class="Stile1"><b>2. Altezza Statua:</b></span><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><input type="text"name="height" size="10" value="<?php htmlspecialchars($height);?>"></div><br/><br/>
    <div align="center"><b>3.</b>&nbsp;<input type="submit" value="Proporzione"></div></td>
    </tr>
    <tr>
    <td bgcolor="#33CCFF"><p class="Stile1">Il risultato ottenuto</p>
      <div align="center"><span class="Stile1"><b>Risultato Proporzione:</b></span><b>&nbsp;</b>
        <input type="text" name="total" size="10" value="<?php htmlspecialchars($total);?>"></div></td>
    </tr>
    <tr>
    <td height="61" bgcolor="#dddddd"><span class="Stile1">L'height &egrave; stata impostata.</span></td>
    </tr>
    </table>
    </form>

    What is wrong?

Viewing 6 replies - 1 through 6 (of 6 total)
  • If you remove the PHP tags, it should work, con you confirm?
    And then we can continue from there.

    Thread Starter Leinad4Mind

    (@leinad4mind)

    Well, with only this:

    <form action="" method="POST" style="padding-top:0px">
    <table border="1" bordercolor="#000000" style="max-width:500px;">
    <tr>
    <td width="20%" bgcolor="#dddddd"><span class="Stile1"><b>Come calcolare le Proporzioni del Presepe?</b><br/>
      </span>
      <p class="Stile1">Inserire nella casella &quot;Dimensione real&quot; la misura espressa in cm di ci&ograve; che volete realizzare. Esempio per un muro di 1 metro dovremo inserire 100 cm</p>
      <div align="center"><b><span class="Stile1">1. Dimensione real:</span>&nbsp;</b><input type="text" name="real" size="10" value=""></div><br/><br/>
    <p class="Stile1">Inserire l'height della statuetta espressa sempre in cm</p><div align="center"><span class="Stile1"><b>2. Altezza Statua:</b></span><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><input type="text"name="height" size="10" value=""></div><br/><br/>
    <div align="center"><b>3.</b>&nbsp;<input type="submit" value="Ottieni Proporzione"></div></td>
    </tr>
    <tr>
    <td bgcolor="#33CCFF"><p class="Stile1">Il risultato ottenuto nella casella &quot;proporzione&quot; &egrave; la misura del muretto in proporzione alla statuetta</p>
      <div align="center"><span class="Stile1"><b>Risultato della Proporzione:</b></span><b>&nbsp;</b>
        <input type="text" name="total" size="10" value=""></div></td>
    </tr>
    <tr>
    <td height="61" bgcolor="#dddddd"><span class="Stile1">L'height &egrave; stata impostata come default a 170 cm height media dell'uomo.</span></td>
    </tr>
    </table>
    </form>

    This code is just HTML, and if I have the “PHP Code” marked at the plugin option, still the same error.
    If I remove the PHP Code mark, then this last html will appear. (But will not work as intended)

    If I remove the php code mark and put the 1st code instead, then on the value space it will appear: <?php echo htmlspecialchars($real);?>

    View post on imgur.com

    Best Regards

    PS: This code worked in the past with php-code-for-posts plugin. If that matters.

    • This reply was modified 8 years, 5 months ago by Leinad4Mind.
    Thread Starter Leinad4Mind

    (@leinad4mind)

    On the ShortCode.php I thought on changing the:
    eval($content);
    to
    eval(' ?>' . $content . '<?php ' );

    But it didn’t work :/

    Thread Starter Leinad4Mind

    (@leinad4mind)

    I’ve thought of a workaround:

    I created 2 snipets. One just for the 1st block content just php:

    <?php
    	if (isset($_POST['real'])){
    		$real=$_POST['real']; //Get the global variable of the first number
    		$height=$_POST['height']; //Get the global variable of the second number
    		if ($real!=null or $height!=null){ //I continue if at least one number is defined
    			if ($real==null){ $real=0; } //If the first number is null, I associate it with zero
    			if ($height==null){ $height=0; } //If the second number is null, I associate it with zero
    			$total=$real*$height/170; //High numbers and define $total (result)
    			$total=round($total,2);
    		}
    	}
    	else{
    	$real=0;
    	$height=0;
    	$total=0;
    	}
    ?>

    And then I created another snippet for the HTML code (that still have some php inside):

    <form action="<?php htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST" style="padding-top:0px">
    <table border="1" bordercolor="#000000" style="max-width:500px;">
    <tr>
    <td width="20%" bgcolor="#dddddd"><span class="Stile1"><b>Come calcolare le Proporzioni?</b><br/>
      </span>
      <p class="Stile1">Inserire nella casella &quot;Dimensione real&quot;</p>
      <div align="center"><b><span class="Stile1">1. Dimensione real:</span>&nbsp;</b><input type="text" name="real" size="10" value="<?php htmlspecialchars($real);?>"></div><br/><br/>
    <p class="Stile1">Inserire l'height</p><div align="center"><span class="Stile1"><b>2. Altezza Statua:</b></span><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><input type="text"name="height" size="10" value="<?php htmlspecialchars($height);?>"></div><br/><br/>
    <div align="center"><b>3.</b>&nbsp;<input type="submit" value="Proporzione"></div></td>
    </tr>
    <tr>
    <td bgcolor="#33CCFF"><p class="Stile1">Il risultato ottenuto</p>
      <div align="center"><span class="Stile1"><b>Risultato Proporzione:</b></span><b>&nbsp;</b>
        <input type="text" name="total" size="10" value="<?php htmlspecialchars($total);?>"></div></td>
    </tr>
    <tr>
    <td height="61" bgcolor="#dddddd"><span class="Stile1">L'height &egrave; stata impostata.</span></td>
    </tr>
    </table>
    </form>

    And I did do this change:

    On the ShortCode.php I thought on changing the:
    eval($content);
    to
    eval(‘ ?>’ . $content . ‘<?php ‘ );

    And therefore since it has php code in both I’ve put the mark on the “PHP Code”.

    It appears without error, but when I click submit it refresh the page but doesnt give the result. :/

    • This reply was modified 8 years, 5 months ago by Leinad4Mind.

    I believe there is no support for PHP opening and closing tags, see:
    https://github.com/davdebcom/post-snippets/issues/36

    I have made a note that we will research this in the coming weeks, but that might be too far away for you. You might need to consider using another plugin with PHP and shortcodes support…

    In your last iteration: are you using the console in the browser to see if the data is being posted at all?

    Thread Starter Leinad4Mind

    (@leinad4mind)

    I didn’t check the console yet.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Eval error’ is closed to new replies.