A quick one

Hi guys…
I have a log in system and when you log in you can edit your profile, I just have one problem;
Since its dynamic link you can just change link at the top and start editing someone elses profile!

I tried to solve this problem like this;

if(isset($user)) // Edit profile
{
if(isset($_GET["edit"]))
{
    // First lets make sure the user is logged in
    if (isLoggedIn() == $user)
    {
        if(isset($_GET["update"]))
        {
            require_once("functions/DbConnector.php");
            $username = $user;
            $db = new DbConnector();
            $db->connect();
            $presentation = $_POST["presentation"];
            $query = "UPDATE login SET presentation='$presentation' WHERE username='$username'";
            $result = $db->query($query);
            echo "Profile updated!";
        } else { // Display edit box
            require_once("functions/DbConnector.php");
            $username = $user;
            $db = new DbConnector();
            $db->connect();
            $query = "SELECT * FROM login WHERE username='$username'";
            $result = $db->query($query);
            $rows = $db->fetchArray($result);
            echo "<center><br/><b>Edit profile</b><br/><form action=\"member.php?edit=".$user."&update\" method='POST'><textarea name='presentation' rows='10' cols='80' align='center'>"
            .$rows["presentation"].
            "</textarea><br/>
            <input type='submit' value='Update Profile' name='submit'>
            </form>
            </center>
            ";
        }
    } 
}
}

But instead I cant now even edit my own profile.

Here is the old code if anyone needs it:

if(isset($_GET["edit"])) // Edit profile
{    
    // First lets make sure the user is logged in     
    if(session_is_registered("username") && session_is_registered ("user_password") && $_SESSION["username"] == $_GET["edit"])
    {
        if(isset($_GET["update"]))
        {
            require_once("functions/DbConnector.php");
            $username = $_GET["edit"];
            $db = new DbConnector();
            $db->connect();
            $presentation = $_POST["presentation"];
            $query = "UPDATE login SET presentation='$presentation' WHERE username='$username'";
            $result = $db->query($query);
            echo "Profile updated!";        
        }
        else 
        {    // Display edit box
            require_once("functions/DbConnector.php");
            $username = $_GET["edit"];
            $db = new DbConnector();
            $db->connect();
            $query = "SELECT * FROM login WHERE username='$username'";
            $result = $db->query($query);
            $rows = $db->fetchArray($result);
            echo "<center><br/><b>Edit your profile</b><br/>
                <form action=\"member.php?edit=".$_GET["edit"]."&update\" method='POST'>
                    <textarea name='presentation' rows='10' cols='80' align='left'>"
                    .$rows["presentation"].
                    "</textarea><br/>
                    <input type='submit' value='Update' name='submit'>
                </form>
                </center>
            ";
                  }
    }
}

All I want to be changed is that the users can edit any other profiles but their own =)

The best way to solve your problem is to use the session variables.
Put session_start() in the first line of your php file. In the login save the users name in the session and check if the user that is being editted is the same as the logged in user saved in the session.
Anyhow this is also the way to go if you want to check if a user has logged in.

Yes, sorry I forgot to say that, but this is just a part of the code, I allredy sessioned the username and I do of course have start session. As you can see this is just I been trying to do in the script, but for some reason it doesn’t work:(

ok, but what is this then?

if(isset($user))
where did you set this var?

i would expect something like
if( $_GET[‘USER’] == $_SESSION[‘user’] )
{

}

Well, I changed my code to this;


if( $_GET['edit'] == $_SESSION['username'] )
{

if(isset($_GET["edit"])) // Edit profile
{    
    // First lets make sure the user is logged in     
    if(session_is_registered("username") && session_is_registered ("user_password") && $_SESSION["username"] == $_GET["edit"])
    {
        if(isset($_GET["update"]))
        {
            require_once("functions/DbConnector.php");
            $username = $_GET["edit"];
            $db = new DbConnector();
            $db->connect();
            $presentation = $_POST["presentation"];
            $query = "UPDATE login SET presentation='$presentation' WHERE username='$username'";
            $result = $db->query($query);
            echo "Profile updated!";        
        }
        else 
        {    // Display edit box
            require_once("functions/DbConnector.php");
            $username = $_GET["edit"];
            $db = new DbConnector();
            $db->connect();
            $query = "SELECT * FROM login WHERE username='$username'";
            $result = $db->query($query);
            $rows = $db->fetchArray($result);
            echo "<center><br/><b>Edit your profile</b><br/>
                <form action=\"member.php?edit=".$_GET["edit"]."&update\" method='POST'>
                    <textarea name='presentation' rows='10' cols='80' align='left'>"
                    .$rows["presentation"].
                    "</textarea><br/>
                    <input type='submit' value='Update' name='submit'>
                </form>
                </center>
            ";
                  }
    }
} else { echo "Error message goes here!"; }
}

But now the edit box is just blank, I cant see the box :frowning:

is the textarea blank or the textarea doesnt even appear?

It doesnt appear…

[QUOTE=Valerij;2340706]It doesnt appear…[/QUOTE]

You have to find out if it is at least going through the else statement. I always throw in an echo just to check if that part of the code is getting processed. add this echo and let me know if the BLAH is displayed. if it’s not, then it’s not even going throught the else statement.

or you could just check your source in the browser and see if the form tags are there.


else 
        {    // Display edit box
            require_once("functions/DbConnector.php");
            $username = $_GET["edit"];
            $db = new DbConnector();
            $db->connect();
            $query = "SELECT * FROM login WHERE username='$username'";
            $result = $db->query($query);
            $rows = $db->fetchArray($result);
            echo "<center><br/><b>Edit your profile</b><br/>
                <form action=\"member.php?edit=".$_GET["edit"]."&update\" method='POST'>
                    <textarea name='presentation' rows='10' cols='80' align='left'>"
                    .$rows["presentation"].
                    "</textarea><br/>
                    <input type='submit' value='Update' name='submit'>
                </form>
echo 'BLAH!';
                </center>
            ";
                  }

No form in the source code, and no BLAH! When I tried your code =/

[QUOTE=Valerij;2340720]No form in the source code, and no BLAH! When I tried your code =/[/QUOTE]

Then it’s not even going through the else statement and that’s why the textarea doesnt come out.

try this…

if( $_GET['edit'] == $_SESSION['username'] )
{

if(isset($_GET["edit"])) // Edit profile
{    
    // First lets make sure the user is logged in     
    if(session_is_registered("username") && session_is_registered ("user_password") && $_SESSION["username"] == $_GET["edit"])
    {

// TESTING IF ITS GOING THROUGH THIS IF STATEMENT
echo 'BLAH!';

        if(isset($_GET["update"]))
        {
            require_once("functions/DbConnector.php");
            $username = $_GET["edit"];
            $db = new DbConnector();
            $db->connect();
            $presentation = $_POST["presentation"];
            $query = "UPDATE login SET presentation='$presentation' WHERE username='$username'";
            $result = $db->query($query);
            echo "Profile updated!";        
        }
        else 
        {    // Display edit box
            require_once("functions/DbConnector.php");
            $username = $_GET["edit"];
            $db = new DbConnector();
            $db->connect();
            $query = "SELECT * FROM login WHERE username='$username'";
            $result = $db->query($query);
            $rows = $db->fetchArray($result);
            echo "<center><br/><b>Edit your profile</b><br/>
                <form action=\"member.php?edit=".$_GET["edit"]."&update\" method='POST'>
                    <textarea name='presentation' rows='10' cols='80' align='left'>"
                    .$rows["presentation"].
                    "</textarea><br/>
                    <input type='submit' value='Update' name='submit'>
                </form>
                </center>
            ";
                  }
    }
} else { echo "Error message goes here!"; }
}  

Let me know if the BLAH is displayed

No, still nothing…

[QUOTE=Valerij;2340735]No, still nothing…[/QUOTE]

Ok, lets just do this…

if( $_GET['edit'] == $_SESSION['username'] ) 
{ 
echo 'TEST 1 PASSED';
if(isset($_GET["edit"])) // Edit profile 
{     
echo 'TEST 2 PASSED';
    // First lets make sure the user is logged in      
    if(session_is_registered("username") && session_is_registered ("user_password") && $_SESSION["username"] == $_GET["edit"]) 
    { 
echo 'TEST 3 PASSED';
        if(isset($_GET["update"])) 
        { 
echo 'TEST 4 PASSED';
            require_once("functions/DbConnector.php"); 
            $username = $_GET["edit"]; 
            $db = new DbConnector(); 
            $db->connect(); 
            $presentation = $_POST["presentation"]; 
            $query = "UPDATE login SET presentation='$presentation' WHERE username='$username'"; 
            $result = $db->query($query); 
            echo "Profile updated!";         
        } 
        else  
        {    // Display edit box 
            require_once("functions/DbConnector.php"); 
            $username = $_GET["edit"]; 
            $db = new DbConnector(); 
            $db->connect(); 
            $query = "SELECT * FROM login WHERE username='$username'"; 
            $result = $db->query($query); 
            $rows = $db->fetchArray($result); 
            echo "<center><br/><b>Edit your profile</b><br/> 
                <form action=\"member.php?edit=".$_GET["edit"]."&update\" method='POST'> 
                    <textarea name='presentation' rows='10' cols='80' align='left'>" 
                    .$rows["presentation"]. 
                    "</textarea><br/> 
                    <input type='submit' value='Update' name='submit'> 
                </form> 
                </center> 
            "; 
                  } 
    } 
} else { echo "Error message goes here!"; } 
}  

Let me know what tests are echoed

Test 1 Passed
Test 2 Passed

[QUOTE=Valerij;2340765]Test 1 Passed
Test 2 Passed[/QUOTE]

Obviously, this statement is resulting in false

if(session_is_registered("username") && session_is_registered ("user_password") && $_SESSION["username"] == $_GET["edit"])

Analyze that if statement. you can probably echo those variables BEFORE THE STATEMENT to see what they contain and see why the if statement is resulting in false.

like this:


echo 'username: '.$_SESSION['username'].'<br />';
echo 'user_password: '.$_SESSION['user_password'].'<br />';
echo 'GET edit: '.$_GET['edit'].'<br />';

You can also try this instead

if(isset($_SESSION['username']) && isset($_SESSION['user_password']) && $_SESSION["username"] == $_GET["edit"])

Let me know what you get.

echo 'username: '.$_SESSION['username'].'<br />';
echo 'user_password: '.$_SESSION['user_password'].'<br />';
echo 'GET edit: '.$_GET['edit'].'<br />';  

Worked perfect! I could also see my edit box and it works =)

if(isset($_SESSION['username']) && isset($_SESSION['user_password']) && $_SESSION["username"] == $_GET["edit"])  

Didnt make any change.
</span></span>

[QUOTE=Valerij;2340774]

echo 'username: '.$_SESSION['username'].'<br />';
echo 'user_password: '.$_SESSION['user_password'].'<br />';
echo 'GET edit: '.$_GET['edit'].'<br />';  

Worked perfect! I could also see my edit box and it works =)

if(isset($_SESSION['username']) && isset($_SESSION['user_password']) && $_SESSION["username"] == $_GET["edit"])  

Didnt make any change.
</span></span>[/QUOTE]

Just curiosity… why were you using session_is_registered ?

So everything works now?

Yes, everything works now, thanks a lot =D

I wasnt really using session_is_registered, someone told me to try that and see if that helps, and then I forgot to remove it when I create this thread.