回显多个div时,php页面为黑色

Every time I try and echo multiple divs useing php the page loads completly blank. I don't understand what im doing wrong. Can someone please help me resolve this problem, I am new to php and can't figure this out. -Thanks in advanced

echo '<div id="id01" class="w3-modal">
<div class="w3-modal-content">
  <div class="w3-container">
    <span onclick="document.getElementById('id01').style.display='none'" class="w3-button w3-display-topright">&times;</span><center><form method='POST' action='".setComments($conn)."'>
<textarea name='title'></textarea>
    <input type='hidden' name='uid' value='".$_SESSION['username']."'>
    <input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<textarea name='description'></textarea>        
<textarea name='message'></textarea>
    <br>
    <button type='submit' name='commentSubmit'>Post!</button>
</form></center>
</div>
</div>
</div>
</div>';

^ Above is the code that is not working correctly (the page loads blank) ^

This will work

echo '<div id="id01" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById(\'id01\').style.display=\'none\'" class="w3-button w3-display-topright">&times;</span><center><form method=\'POST\' action=\''.setComments($conn).'\'>
<textarea name=\'title\'></textarea>
<input type=\'hidden\' name=\'uid\' value=\''. $_SESSION['username'] . '\'>
<input type=\'hidden\' name=\'date\' value=\'' .date('Y-m-d H:i:s'). '\'>
<textarea name=\'description\'></textarea>        
<textarea name=\'message\'></textarea><br> <button type=\'submit\' name=\'commentSubmit\'>Post!</button>
</form></center>
</div>
</div>
</div>
</div>';

But you should revise this code. Its too complicated thus error prone.

Cheers

Check your quotes.

You are echoing between single quotes '. Every time you add an unescaped (\) single quote, you break the string you are echoing.

Either use " (name="title" etc.) or escape the 's (getElementById(\'id01\').

This bit for example, remembering your original quotes are single:

<form method='POST' action='".setComments($conn)."'>

should be

<form method="POST" action="'.setComments($conn).'">

The page being blank is ultimately the result of a server error, due to malformed php, due in your case to the broken up echo instruction.

Have you tried to echo all the different lines?: Also has another answer check the quotes i noticed that too!

Either use " (name="title" etc.) or escape the 's (getElementById(\'id01\'). This bit for example, remembering your original quotes are single:

<form method='POST' action='".setComments($conn)."'>

should be

<form method="POST" action="'.setComments($conn).'">
<?php
echo "<div id=\"id01\" class=\"w3-modal\">
"; 
echo "<div class=\"w3-modal-content\">
"; 
echo "  <div class=\"w3-container\">
"; 
echo "    <span onclick=\"document.getElementById('id01').style.display='none'\" class=\"w3-button w3-display-topright\">&times;</span><center><form method='POST' action='\".setComments($conn).\"'>
"; 
echo "<textarea name='title'></textarea>
"; 
echo "    <input type='hidden' name='uid' value='\".$_SESSION['username'].\"'>
"; 
echo "    <input type='hidden' name='date' value='\".date('Y-m-d  H:i:s').\"'>
"; 
echo "<textarea name='description'></textarea>        
"; 
echo "<textarea name='message'></textarea>
"; 
echo "    <br>
"; 
echo "    <button type='submit' name='commentSubmit'>Post!</button>
"; 
echo "</form></center>
"; 
echo "</div>
"; 
echo "</div>
"; 
echo "</div>
"; 
echo "</div>
";
?>