user652792
user652792

Reputation:

Form not displaying for logged in users

Please i need your help with my script. I'm trying to post comments to news items on sections on my website only for users who are logged in. If they are not, they are shown a link to Login or Register, and the "Post A Comment" inputbox does not display. Then when they login the form should display.

The form does not display, when they are not logged in, but it does not also show the form when they are logged in.

Please where could the broblem be.. Thank you for your time and patience. I apppreciate it.

 <?php 

if (!isset($_SESSION['username']))  {

echo "<a href=\"login.php\">Login</a>     OR <a href=\"register.php\">Register</      a> to make a comment" ; 
             }
             exit();
 ?>






  <?php

  if (isset($_POST['submit'])) {

     //process form

             }

           ?>
     Post A Comment <br/>  
      <form action="<?php echo $_SERVER       ['PHP_SELF']; ?>" method="post"> 
                    <textarea type="text"  name                  = "comment_body" title='Post A      Comment'  class='OpenInput_Text'  ></       textarea><br/> 
 <input type="submit" name="submit"      value="Post Comment"> 
 </form>  
 </div> 
 </div> 

Upvotes: 0

Views: 105

Answers (3)

MakuraYami
MakuraYami

Reputation: 3428

Move the exit() inside if (!isset($_SESSION['username'])) { ... } instead of after it.

Upvotes: 0

Kescha Skywalker
Kescha Skywalker

Reputation: 489

.. It's because you are exiting the script in with an

exit();

I think you want to push it one line up, to end the script if the user is not logged in.

Upvotes: 0

Devator
Devator

Reputation: 3904

You will need to start your sessions.

Replace

<?php 

if (!isset($_SESSION['username']))  {

With

<?php 
session_start();
if (!isset($_SESSION['username']))  {

Upvotes: 1

Related Questions