Jump to content

Profile page PHP


phpnewbei

Recommended Posts

Need some help with Profile page, it goes like this:

<html>
<head>
<style type="text/css" media="all">
@import url("style.css");
</style>
</head>
<body>
<div id="header">
<h1><a href="index.php">ProjecTM</a></h1>
</div>
<div id="menu">
<ul>
<a href="index.php">News</a>
<a href="guestbook.php">Guestbook</a>
<a href="changepassword.php">Change Password</a>
<a href="logout.php">Log out</a>
</ul>
</div>
<?php
include("dbconnect.php");
session_start();
echo "<div id=\"homeform\">";
if(isset($_SESSION["username"])){
$link1 ='
<a href="members.php?uname&changeinfo=' . $_SESSION["username"] . '"> Change information </a>';
if($_SESSION["username"] == isset($_GET["uname"])){
echo "hej";
}
elseif ($_SESSION["username"] != isset($_GET["uname"])) {
echo "hejdå";
}
}
echo "</div>";
?>
</body>
</html>

 

THe link to the profile page goes like this:

echo "<a href=\"members.php?uname=" . $user . "\">Your page</a>";

Link to comment
Share on other sites

I've done that now, but it still don't work cuz in my address field

When I'm logged in as "Machram" and click in my profile the address field is : http://localhost/project/members.php?uname=Machram

 

When I go to like "http://localhost/project/members.php?uname=Test"

It still says the same thing on the page :P "Echo "Hello";"

Link to comment
Share on other sites

$uname = isset($_GET['uname']) ? $_GET['uname'] : 'guest';

 

means

 

if (isset($_GET['uname'])) {  // if uname variable is supplied by the GET request

    $uname = $_GET['uname'];

} else {

    $uname = 'guest';  // if uname was not supplied we set it to 'guest'

}

 

after that you should use ... $_SESSION['username'] == $uname (instead of $_GET['uname'])

Link to comment
Share on other sites

Now I have an UPDATE error heh, here's my code:

 

elseif ($_SESSION["username"] == (isset($_GET["changeinfo"]))) {$sql = mysql_query("SELECT * FROM userinfo WHERE username='" . $_SESSION["username"] . "'");while($row = mysql_fetch_array($sql)){echo "<form method=\"POST\" action=\"members.php?uname&changeinfo=" . $_SESSION["username"] . "\">";echo "<input type=\"text\" name=\"name\" value=\"" .  $row["firstname"] . "\">";echo "<input type=\"submit\" value=\"Change\">";echo "</form>";$firstname = isset($_POST["name"]);mysql_query("UPDATE userinfo SET firstname='$firstname' WHERE username=" . $_SESSION["username"] . "");}}

 

Link to comment
Share on other sites

Now I have an UPDATE error heh, here's my code:

 

elseif ($_SESSION["username"] == $_GET["changeinfo"]) {
    $sql = mysql_query("SELECT * FROM userinfo WHERE username='" . $_SESSION["username"] . "'");
    while($row = mysql_fetch_array($sql)) {
        echo '<form method="POST" action="members.php?uname&changeinfo="' . $_SESSION["username"] . '">';
        echo '<input type="text" name="name" value="' .  $row["firstname"] . '">';
        echo '<input type="submit" value="Change">';
        echo '</form>';
        $firstname = $_POST["name"];
        mysql_query("UPDATE userinfo SET firstname='$firstname' WHERE username='" . $_SESSION["username"] . "'");
    }
}

Link to comment
Share on other sites

Now, If I write something in my input fields and update, it works, but when I go back and change the information again, the field in my database gets emtpy :S

My guess would be that when the database have been update, nothing happends, you'll return to the input field again.

Link to comment
Share on other sites

<?php
echo "<div id=\"homeform\">";
if(isset($_SESSION["username"])){
$link1 ='
<a href="members.php?uname&changeinfo=' . $_SESSION["username"] . '"> Change information </a>';
$uname = isset($_GET['uname']) ? $_GET['uname'] : 'guest';
if($_SESSION["username"] == $uname){
echo "hej";
echo $link1;

}
elseif ($_SESSION["username"] == $_GET["changeinfo"]) {
$sql = mysql_query("SELECT * FROM userinfo WHERE username='" . $_SESSION["username"] . "'");
while($row = mysql_fetch_array($sql)){
echo '<form method="POST" action="members.php?uname&changeinfo=' . $_SESSION["username"] . '">';
echo '<input type="text" name="name" value=' .  $row["firstname"] . '>';
echo '<input type="submit" name="submit" value="Change">';
echo '</form>';
$firstname = $_POST["name"];
mysql_query("UPDATE userinfo SET firstname='$firstname' WHERE username='" . $_SESSION["username"] . "'");
}
if($_POST["submit"])
{
echo "Success!";
}
}
else {
echo "du suger";
}
echo "</div>";
}
?>

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.