-2

This code is a part my webpage:

<span onclick=alert('Name:$commenter_name <br>Email:$commenter_email <br> Rate:$commenter_rate <br>Comment time:$currentdate <br>Comment:$commenter_comment')>$commenter_name:$commenter_comment
    <span class='post_time'>$currentdate</span>
</span>

The JavaScript alert is not working.

I want to make this code working, without using any double quotes.

Here's my whole PHP code:

<?php
    if (isset($_POST['post'])){    
        $commenter_name = $_POST["commenter_name"];
        $commenter_email = $_POST["commenter_email"];
        $commenter_rate = $_POST["commenter_rate"];
        $commenter_comment = $_POST["commenter_comment"];
        $currentdate = date('d F Y');
        $fianl = "Name:$commenter_name <br>Email:$commenter_email <br> Rate:$commenter_rate <br>Comment time:$currentdate<br>Comment:$commenter_comment";
        $filename = getcwd() . "/Comma comments.php"; 
        $line_i_am_looking_for = 2; 
        $lines = file( $filename , FILE_IGNORE_NEW_LINES ); 
        $lines[$line_i_am_looking_for] =    "
        <tr>
            <td>
                 <span onclick=alert('$fianl')>$commenter_name$commenter_comment
                      <span class='post_time'> $currentdate </span>
                 </span><hr><br>
           </td>
        </tr>";
       file_put_contents( $filename , implode( "\n", $lines ) );
    }
?>

Please help

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

I've made the answer myself. Here's the code:

<?php
if (isset($_POST['post'])){

        $commenter_name = $_POST["commenter_name"];
        $commenter_email = $_POST["commenter_email"];
        $commenter_rate = $_POST["commenter_rate"];
        $commenter_comment = $_POST["commenter_comment"];
        $currentdate = date('d F Y');
        $fianl = "Name\:$commenter_name \\n Email\:$commenter_email \\n Rate\:$commenter_rate \\n Comment time\:$currentdate \\n Comment\:$commenter_comment";
$filename = getcwd() . "/Comma comments.php"; 
$line_i_am_looking_for = 2; 
$lines = file( $filename , FILE_IGNORE_NEW_LINES ); 
$lines[$line_i_am_looking_for] =    "
<tr>
 <td colspan='2'>
 <span onclick=\"alert('$fianl')\">$commenter_name$commenter_comment <span class='post_time'> $currentdate </span></span><hr>
<br>
</td></tr>";
file_put_contents( $filename , implode( "\n", $lines ) );
}
?>

\" tells the PHP script to ignore the double quotes. \\n tells the PHP script to ignore \n. That's all.