Jump to content

php edit when logged in not working


mrooks1984

Recommended Posts

hello i am stuck and hoping you can help, i have created this function and its not working correctly, what i am trying to do is

when someone is logged in they get this line of code echo "<a href=\"update-content.php?id=5\">Edit</a> | <a href=\"delete-content.php?id=5\">Delete</a>"; which is ok as i dont want that to work yet and if your not logged in you dont get it.

i have added //show when logged in and show not logged in so you know which code i want it to load when

at the moment its only loading the not logged in one even if you are.

i have looked on google read up on php sites but cant figure out how to do it, so hoping you guys will tell me were i gone wrong and how to correct it, thanks again

 

heres the code.

	function get_left() {

        if (isset($_GET['page']))
{
		$page = $_GET['page'];


					//Show Page not logged in
                $sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id";
                $res = mysql_query($sql) or die (mysql_error());
                while($row = mysql_fetch_assoc($res)){
				echo '<h1>' . $row['title'] . '</h1>';
                    echo '<p>' . $row['body'] . '</p>'; 

			}	

}
//show when logged in
elseif ($_SESSION['username']&&(isset($_GET['page']))){
		$sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id";
                $res = mysql_query($sql) or die (mysql_error());
                while($row = mysql_fetch_assoc($res)){
				echo '<h1>' . $row['title'] . '</h1>';	
                    echo '<p>' . $row['body'] . '</p>';
				echo "<a href=\"update-content.php?id=5\">Edit</a> | <a href=\"delete-content.php?id=5\">Delete</a>"; 
			}
}
}

Link to comment
Share on other sites

As a start, your IF and your ELSEIF both check to see if $_GET page is set, if it is, then the ELSEIF will never execute as the first portion will kick-in - you need to rethink the order ie first if BOTH username and page are set do this - if only page is set do that.

Link to comment
Share on other sites

Simply reverse the if and elseif conditions - FIRST check to see if username and page are set then in the elseif check to see if the page is set.

 

By reversing the order, if username not set, it will then check if the page is set in the elseif.

 

Of course you haven't provided for the condition where neither is set.

 

capice?

Link to comment
Share on other sites

thanks for your help again

ok i now have this, when logged in it shows the correct stuff, if i then log out it does not show anything at all?

i must be missing something elise?

function get_left() {

        if ($_SESSION['username']&&(isset($_GET['page'])))

{

$page = $_GET['page'];

//Show Page not logged in

                $sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id";

                $res = mysql_query($sql) or die (mysql_error());

                while($row = mysql_fetch_assoc($res)){

echo '<h1>' . $row['title'] . '</h1>';

                    echo '<p>' . $row['body'] . '</p>';

echo "<a href=\"update-content.php?id=5\">Edit</a> | <a href=\"delete-content.php?id=5\">Delete</a>";

}

}

//show when logged in

elseif (isset($_GET['page'])){

$sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id";

                $res = mysql_query($sql) or die (mysql_error());

                while($row = mysql_fetch_assoc($res)){

echo '<h1>' . $row['title'] . '</h1>';

                    echo '<p>' . $row['body'] . '</p>';

}

}

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.