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
https://forums.phpfreaks.com/topic/214524-profile-page-php/
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
https://forums.phpfreaks.com/topic/214524-profile-page-php/#findComment-1116298
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
https://forums.phpfreaks.com/topic/214524-profile-page-php/#findComment-1116307
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
https://forums.phpfreaks.com/topic/214524-profile-page-php/#findComment-1116319
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
https://forums.phpfreaks.com/topic/214524-profile-page-php/#findComment-1116327
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
https://forums.phpfreaks.com/topic/214524-profile-page-php/#findComment-1116337
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
https://forums.phpfreaks.com/topic/214524-profile-page-php/#findComment-1116389
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.