-1

I am trying to display data from a mysql table inside a which is inside a but i get a syntax error in the echos where i start to display the $data and i can't really understand why , here's the code :

while ($data = mysql_fetch_array($req)) {
  echo'<div class="row">';
    echo'<input type="radio" name="expand">';
    echo '<span class="cell primary" data-label="Date">'$data['date']'</span>';
   echo'<span class="cell" data-label="Titre"> <a href="read_msg.php?id_msg_usr='$data['id_msg_usr']'"> </span>';
     echo'<span class="cell" data-label="Fromm">'stripslashes(htmlentities(trim($data['fromm'])))'</span>';
  echo'</div>';

Thanks for your help

  • and the syntax error is .... ? – devlin carnate May 03 '16 at 17:37
  • $data['date'] insert ' to top and finish and insert } to after '; – Furkan May 03 '16 at 17:38
  • Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 03 '16 at 18:18
  • Thanks for the advices i will try to read and learn more about that. – Silversprint May 03 '16 at 22:20

2 Answers2

0

You forgot to put dots in so many places...

while ($data = mysql_fetch_array($req)) {
    echo '<div class="row">';
    echo '<input type="radio" name="expand">';
    echo '<span class="cell primary" data-label="Date">'.$data['date'].'</span>';
    echo '<span class="cell" data-label="Titre"> <a href="read_msg.php?id_msg_usr='.$data['id_msg_usr'].'"> </span>';
    echo '<span class="cell" data-label="Fromm">'.stripslashes(htmlentities(trim($data['fromm']))).'</span>';
    echo'</div>';
}
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29
0

You're missing some concatenation dots (.) and a closing parenthesis ).
Use php heredoc to avoid this kind of errors, i.e.:

while ($data = mysql_fetch_array($req)) {
$fromm = stripslashes(htmlentities(trim($data['fromm'])));
$id_msg_usr = $data['id_msg_usr'];
echo <<< LOL
<div class="row">
   <input type="radio" name="expand">
   <span class="cell primary" data-label="Date">{$fromm}</span>
   <span class="cell" data-label="Fromm">{$id_msg_usr}</span>
</div>
LOL;
}

PS: is fromm correct or should it be from only?

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268