Note that there are some explanatory texts on larger screens.

plurals
  1. POphp variable gets null at the end of the script?
    primarykey
    data
    text
    <p>I have a problem that I really can't figure out. basically I'm working on a blog and I have a variable from a cookie that returns a post id. the problem is that at the end of the script, when I enter an if(isset) statement, the variable seems to be null and I can't understand the reason behind it. it won't add anything to the database and it won't redirect to the post id. here's the script:</p> <pre><code>&lt;?php //display the post $post_id = $_GET['post_id']; $query = mysql_query("SELECT * FROM posts WHERE `post_id`='". $post_id. "';") or die(mysql_error()); if(mysql_num_rows($query) != 0) { $currentrow = mysql_fetch_array($query); echo $currentrow['title']. "&lt;br&gt;". $currentrow['text']; } else { echo "that post does not exist."; } ?&gt; &lt;/div&gt; &lt;div id="comments"&gt; &lt;br&gt; &lt;h3&gt;Comments&lt;/h3&gt; &lt;br&gt; &lt;?php //display the comments $comments = mysql_query("SELECT * FROM `comments` JOIN `posts` ON(posts.post_id=comments.post_id) JOIN `users` ON(users.user_id=comments.user_id) WHERE posts.post_id=". "'". $_GET['post_id']. "'". ";")or die(mysql_error());; while($currentRow = mysql_fetch_array($comments)) { echo $currentRow['ctext']. "&lt;br&gt;"; echo "posted by &lt;a href='/templates/profile.php?name=". $currentRow['name']. "'&gt;". $currentRow['name']. "&lt;/a&gt; at ". $currentRow['cdate']. " -- ". $currentRow['ctime']. "&lt;br&gt;&lt;br&gt;"; } ?&gt; &lt;/div&gt; &lt;Form Name ="submitform" Method ="POST" ACTION = "post.php"&gt; &lt;div id="commentbox"&gt; &lt;textarea name="textarea1" rows="10" cols="30"&gt; &lt;?php echo $post_id; ?&gt; &lt;/textarea&gt; &lt;br&gt; &lt;input type="submit" name="submitcomment" value="Submit"&gt;&lt;br&gt; &lt;/div&gt; &lt;/Form&gt; &lt;?php if(isset($_POST['submitcomment'])) { $comment = $_POST['textarea1']; $user_id = $_COOKIE['userid']; mysql_query("INSERT INTO comments(`ctext`, `cdate`, `ctime`, `user_id`, `post_id`) VALUES('$comment', 'CURDATE()', 'CURTIME()', '$user_id', '$post_id')") or die(mysql_error()); header('Location: /post.php?post_id='. $post_id); } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>as you can see, I'm echoing that variable in the textarea1 just before the if statement and it returns the correct value, but at the end it's null. thanks in advance. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload