Hello, I am new to PHP and have been working on a site which I would like to set up some user profiles. I have currently been toying around with the profile page and in order to get better equipped I have been trying to call different information to the tables on the profile page.
I have not had much success. The only success I have is calling the username to the page with this,
if ($_SESSION[‘username’])
{
echo “You are logged in as “.$
I have been trying to call the users email to the page with similar tags and tags I have found on the internet with no luck.
Does anyone have a general rule of commands or some advice on how I can accomplish tasks as simple as calling information from the DB?
I am at some point trying to set up a gallery for users to upload pictures to there profile and I really need some guidance on how to get there.
Thanks!
[code=php]
$username = mysql_real_escape_string(trim($_POST['username']));
$password = mysql_real_escape_string(trim($_POST['password']));
$result = mysql_query( "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1")[/code]
[code=php]while ($row = mysql_fetch_array($result) {
$_SESSION['username'] = $row['username'];
$_SESSION['phone'] = $row['phone'];
$_SESSION['mobile'] = $row['mobile'];
$_SESSION['email'] = $row['email'];
$_SESSION['web'] = $row['web'];
}[/code]
[code=php]session_start();[/code]
at the top of every page where you want to use sessions (before any other php or html code).[code=php]echo "<p><b>Username: $_SESSION['username']</b><br>Phone: $_SESSION['phone']<br>Mobile: $_SESSION['mobile']<br>E-mail: $_SESSION['email']<br>Web: $_SESSION['web']</p><hr>"; [/code]
[code=php]echo "<p><b>Username: " . $_SESSION['username'] . "</b><br>Phone: " . $_SESSION['phone'] . "<br>Mobile: " . $_SESSION['mobile']. "<br>E-mail: " . $_SESSION['email'] . "<br>Web: " . $_SESSION['web']. "</p><hr>";[/code]
[code=php]session_start();[/code]
should be before any other code on your page (PHP or HTML) so starting from line 1:[code=php]<?php
session_start();
?>[/code]
[code=php]echo $row['email'];
var_dump($_SESSION); // to view all session data, or
var_dump($SESSION['email']) // to just view the email
[/code]
[code=php]while ($row = mysql_fetch_array($result)) {[/code]
[code=php] while ($row = mysql_fetch_array($result)) {
//$_SESSION['username'] = $row['username'];
//$_SESSION['phone'] = $row['phone'];
//$_SESSION['mobile'] = $row['mobile'];
//$_SESSION['email'] = $row['email'];
//$_SESSION['web'] = $row['web'];
echo $row['username'];
} [/code]
AND THIS IS THE LOGIN.PHP
$connect = mysql_connect("localhost","root","") or die ("Could not connect to databade.");
mysql_select_db("login") or die ("Could not find database.");
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if($numrows !=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
$dbemail = $row['email'];
}
if ($username==$dbusername&&$password==$dbpassword)
{
echo "Login Successful.<a href='membersarea.php'>Redirecting to the user profile page</a>";
header( "refresh:1;url=home.php" );
$_SESSION['username']=$dbusername;
}
else
echo "Incorrect password";
}
else
die ("that username does not exist");
For instance, when you added $_SESSION its cause you assume based on what I originally sent you that I have already set SESSION up as the variable to call on this information???[/QUOTE]
[code=php]$username = trim($_POST['username']); // same for password[/code]
[code=php]$username
// and
$password[/code]
[code=php]if (isset($_POST['username'])) {
echo $_POST['username'];
} else {
echo 'No username posted';
}[/code]
$connect = mysql_connect("localhost","root","") or die ("Could not connect to databade.");
mysql_select_db("login") or die ("Could not find database.");
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if($numrows !=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
$dbemail = $row['email'];*************ADDED THIS LINE
$dbphone = $row['phone']; *************ADDED THIS LINE
$dbmobile = $row['mobile']; *************ADDED THIS LINE
$dbweb = $row['web']; *************ADDED THIS LINE
}
if ($username==$dbusername&&$password==$dbpassword)
{
echo "Login Successful.<a href='membersarea.php'>Redirecting to the user profile page</a>";***********************I ADDED THIS AREA***************
header( "refresh:1;url=home.php" );
$_SESSION['username']=$dbusername;
$_SESSION['password']=$dbpassword;
$_SESSION['email']=$dbemail;
$_SESSION['phone']=$dbphone;
$_SESSION['mobile']=$dbmobile;
$_SESSION['web']=$dbweb;
}
else
echo "Incorrect password";
}
else
die ("that username does not exist");
[code=php]<?php
$db="login";
$link = mysql_connect("localhost", "root", "");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
if (isset($_POST['username'])) {
echo $_POST['username'];
} else {
echo 'No username posted';
}
if (isset($_POST['password'])) {
echo $_POST['password'];
} else {
echo 'No password posted';
}
$result = mysql_query( "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1")
or die("SELECT Error: ".mysql_error());
while ($row = mysql_fetch_array($result)) {
$_SESSION['username'] = $row['username'];
$_SESSION['phone'] = $row['phone'];
$_SESSION['mobile'] = $row['mobile'];
$_SESSION['email'] = $row['email'];
$_SESSION['web'] = $row['web'];
}
echo "<p><b>Username: " . $_SESSION['username'] . "</b><br>Phone: " . $_SESSION['phone'] . "<br>Mobile: " . $_SESSION['mobile']. "<br>E-mail: " . $_SESSION['email'] . "<br>Web: " . $_SESSION['web']. "</p><hr>";
mysql_close($link);
?>[/code]
[code=php]<?php
session_start();
$username = trim($_POST['username']);
$password = trim($_POST['password']);
if (isset($username) && isset($password))
{
$connect = mysql_connect("localhost","root","") or die ("Could not connect to databade.");
mysql_select_db("login") or die ("Could not find database.");
$query = mysql_query("SELECT * FROM users WHERE username='".mysql_real_escape_string($username)."' and password='".mysql_real_escape_string($password)."' LIMIT 1");
$numrows = mysql_num_rows($query);
if($numrows != 0)
{
while ($row = mysql_fetch_array($query))
{
$_SESSION['username'] = $row['username'];
$_SESSION['email'] = $row['email'];
$_SESSION['phone'] = $row['phone'];
$_SESSION['mobile'] = $row['mobile'];
$_SESSION['web'] = $row['web'];
}
header("location: home.php");
}
else {
echo "Your username and / or password is incorrect";
}
}
else {
echo "Please enter a username and password";
}
?>[/code]
[code=php]var_dump($_POST);[/code]
at the top of your login page and post here exactly what you get back?0.1.9 — BETA 6.1