Getting an syntax error, unexpected T_STRING in select option in html,php -


hi have small project give news past 4,6,10 weeks using select option in html. getting syntax error, unexpected t_string in select option tag. understand error cant use php inside open php tag. dont know how can solve error. help.thanks. here code:

<?php $page['doctype'] = true; $param = array_merge($_get, $_post);  $return = array(); if($param['aktion'] == 'edit-news') {     $page['register-edit-news'] = array(     1   => array( 'edit-news','aktiv',$page['script'],'',''), );   if(isset($_post['btnsubmit']))    {        if(($_post['news'])==4){        $sql=" select distinct ad_news_texte.headline, ad_news.datum_archiv ad_news_texte inner join ad_news_oe on ad_news_texte.news_id = ad_news_oe.id_ad_news inner join ad_news on ad_news_oe.id_ad_news = ad_news.id ad_news.datum_archiv between curdate( ) - interval dayofweek( curdate( ) ) +28 day , curdate( ) ";  $sql_select=mysql_query($sql); while($row = mysql_fetch_array($sql_select)) {   echo $row['headline'] . " " .$row['datum_archiv'] ;   echo "<br>"; } }   if(($_post['news'])==10){        $sql=" select distinct ad_news_texte.headline, ad_news.datum_archiv ad_news_texte inner join ad_news_oe on ad_news_texte.news_id = ad_news_oe.id_ad_news inner join ad_news on ad_news_oe.id_ad_news = ad_news.id ad_news.datum_archiv between curdate( ) - interval dayofweek( curdate( ) ) +70 day , curdate( ) ";  $sql_select=mysql_query($sql); while($row = mysql_fetch_array($sql_select)) {   echo $row['headline'] . " " .$row['datum_archiv'] ;   echo "<br>"; } }    $html =      ' <body bgcolor="#ffffff"> <table width="100%" border="0" cellspacing="0" cellpadding="0">  <tr> <td class="welcome-page-hint">  <table width="538" cellpadding="0" cellspacing="0" border="0"> <tr> <td>  <h3>news</h3>  <form name="userinformationform" method="post" action="#">        <select name="news">          <option value="4" <?php if($_post['news']=="4") echo "selected=selected"; ?>>show news last 4 weeks</option>          <option value="6" <?php if($_post['news']=="6") echo "selected=selected"; ?>>show news last 6 weeks</option>        </select>       <br/><br/>       <input name="btnsubmit" type="submit" value="submit"> </form>  </td> </tr> </table>  </td> </tr>  </table>'; $return = array(         'status' => 1,         'html'  => $html     );      echo(json_encode($return)) ; } ?> 

you can't have php code inside variable in php code.

what should escape string , concatenate.

<option value="4" '. (($_post['news']=="4") ? "selected=selected" : "") .'>show news last 4 weeks</option> <option value="6" '. (($_post['news']=="6") ? "selected=selected" : "") .'>show news last 6 weeks</option> 

instead of trying put new php code block in there have escaped string, used ternary operator , concatenated 3 parts.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -