tags:

views:

132

answers:

3

hi all,

<td align="center" bgcolor="#FFFFFF"><?php echo '<label onclick="window.open('profilephp.php?member=$row['MemberID']','mywindow')">'.{$row['MemberName']}.'</label>';?><br />
<?php  echo "<p align='center'><img width='100' height='100' src={$row['MemberImg']} alt='' /></p>";?></td></tr>

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\home - Copy\membercopy.php on line 141

I really don't know where it went wrong. Please help,

+10  A: 
<?php 

   echo '<label onclick="window.open('profilephp.php?member=$row['MemberID']','mywindow')">'{$row['MemberName']}.'</label>';

?>

If you look at that line, you'll see you have your single quoted string with single quotes inside it. Also, you're trying to use variables inside a single quoted string, which doesn't work. You want to change this to:

   echo "<label onclick=\"window.open('profilephp.php?member={$row['MemberID']}','mywindow')\">'{$row['MemberName']}.'</label>";

Notice I've double quoted your string and then escaped, with a backslash, any double quotes inside the quoted string.

I also added {} around the first complex variable in the string, since it will give you an error without it.

Erik
A: 

This fixes most of the problems with your code (and it's even readable!):

<td style="text-align: center; background-color: #FFFFFF;">
   <label onclick="window.open('profilephp.php?member=<?php=$row['MemberID']?>','mywindow')">
      <?php=$row['MemberName']?>
   </label>
   <br />
   <img src="<?php=$row['MemberImg']?>" width="100" height="100" alt="" />
</td>
Dolph
Feel free to explain the -1.
Dolph
This will throw errors. The JS includes an unquoted string (I'm assuming you don't have a `profilephp` object with a `php` property that you want to use a a ternary operation!
David Dorward
Even if it did work, "Here is some fixed code" means people have to analyze it to figure out the differences in order to determine what the error was so it could be avoided in future.
David Dorward
Conspicuous Compiler and Erik already explained the problems - there's no point in echoing their words. Also, my code did/does not contain the unquoted string issue you referred to. I was, however, completely missing the single quote in question and have restored it.
Dolph
+1  A: 

The error are the non-escaped single quotation marks and the bracets. You write this:

<?php echo '<label onclick="window.open('profilephp.php?member=$row['MemberID']','mywindow')">'.{$row['MemberName']}.'</label>';?>

but is has to look like this:

<?php echo '<label onclick="window.open(\'profilephp.php?member='.$row['MemberID'].'\',\'mywindow\')">'.$row['MemberName'].'</label>';?>

I hope that is what you needed.

Kau-Boy
Doplh Mathews, thanks for your answer, that is exactly as I use to do it.
Kau-Boy