I am trying to use onclick in PHP echo , I arrived at this error
Parse error: syntax error, unexpected 'OpenPopupCenter' (T_STRING) in C:\xampp\htdocs\e-vms\securitydashboard.php on line 229
My code looks like this
<?php
require_once('inc/config.php');
$con = mysqli_connect($host, $user, $pass, $db) or die ('Cannot connect, Reason: '.mysqli_error());
$sql = "select * from new_reservation ";
$result = mysqli_query($con,$sql) or die ('Failed Query , Reason : '.mysqli_error($con));
while($row = mysqli_fetch_array($result)){
$showData = "<TR valign=top>
<TD width=106 height=26><div class=wpmd>
<div align=center><font face=Verdana size=1><BR></font></div>
<div align=center><font face=Verdana size=1> {$row['visit_date']}</font></div>
</div>
</TD>
<TD width=134 height=26><div class=wpmd>
<div align=center><font face=Verdana size=1><BR></font></div>
<div align=center><font face=Verdana size=1> {$row['login_time']}</font></div>
</div>
</TD>
<TD width=148 height=26><div class=wpmd>
<div><font face=Verdana size=1><BR></font></div>
<div><font face=Verdana size=1> {$row['fullname']}</font></div>
</div>
</TD>
<TD width=160 height=26><div class=wpmd>
<div align=center><font face=Verdana size=1><BR></font></div>
<div align=center><font face=Verdana size=1> {$row['whom_tosee']}</font></div>
</div>
</TD>
<TD width=138 height=26><div class=wpmd>
<div> </div>
<div align=center><font face=Verdana><input type=image src=images/show_detailsbtn.png width=124 height=26 onclick="OpenPopupCenter('e-vmsreserve.php', 'TEST!?', 1200, 600);" ></font></div>
</div>
</TD>
<TD width=163 height=26><div class=wpmd>
<div><BR></div>
<div> <font face=Verdana size=2>
<input type=image src=images/signout_visitor.png width=121 height=27></font></div>
</div>
</TD>
</TR>
";
echo $showData;
}
?>
What do i appear to be missing? Should I make some little adjustments it wont even open the window.
-
Possible duplicate of PHP parse/syntax errors; and how to solve them?04FS– 04FS2019年10月22日 08:57:47 +00:00Commented Oct 22, 2019 at 8:57
-
And go read up on some basics, please. php.net/manual/en/language.basic-syntax.phpmode.php There is no real need here to assemble this content in a variable first, only to then do nothing else but outputting it directly afterwards. You wouldn’t have that many problems with string delimiters and escaping in the first place without it.04FS– 04FS2019年10月22日 08:59:57 +00:00Commented Oct 22, 2019 at 8:59
1 Answer 1
Add \before ".
Replace
onclick="OpenPopupCenter('e-vmsreserve.php', 'TEST!?', 1200, 600);"
by
onclick=\"OpenPopupCenter('e-vmsreserve.php', 'TEST!?', 1200, 600);\"
answered Oct 22, 2019 at 8:24
Reqven
1,7981 gold badge10 silver badges13 bronze badges
default