/    Sign up×
Community /Pin to ProfileBookmark

Calling data from the database

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 “.$_
SESSION[‘username’];

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!

to post a comment
PHP

45 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 23.2012 — Well...the information will only be in $_SESSION if your code put it there. So if you want to access it that way, you'll probably need to modify your login processing to add that data element to the $_SESSION array. Otherwise, you'll need to explicitly query the database for that info in any situation where you need it.
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — Ok this is what I have,


<?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());

$result = mysql_query( "SELECT * FROM users" )

or die("SELECT Error: ".mysql_error());

$num_rows = mysql_num_rows($result);

$i=0;


while ($i<$num_rows )


{

$first=mysql_result($result, $i,"first");

$last=mysql_result($result,$i,"last");

$phone=mysql_result($result,$i,"phone");

$mobile=mysql_result($result,$i,"mobile");

$username=mysql_result($result,$i,"username");

$email=mysql_result($result,$i,"email");

$web=mysql_result($result,$i,"web");

$i++;

}

echo "<b>Username: $username</b><br>Phone: $phone<br>Mobile: $mobile<br>E-mail: $email<br>Web: $web<br><hr><br>";&#160;




mysql_close($link);

?>


After this executes it post the most recent person who has registered on the sites information instead of the person who just loged in. I need this to show the persons information who is logged in. Thanks for your help...
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — Well there are a couple of things wrong with your code.

Firstly you should be selecting details from the database based on one user's information not all data (using their login details):

[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]

(if using SHA1 or MD5 to encrypt passwords in your database you need to use that to format your posted passwords)

Then just fetch_array:

[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]


You need to ensure you have [code=php]session_start();[/code] at the top of every page where you want to use sessions (before any other php or html code).

And then you can just echo it out:

[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]
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — This all makes sense to me. thank you.. but I am getting a syntax error here

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>";

This is the error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:xampphtdocspixelprofile.php on line 79
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — Here is the whole code from top to bottom after updating with what you said. Please make sure I changed the correct locations.

session_start();

<?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());


$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")

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 "<b>Username: $_SESSION['username']</b><br>Phone: $_SESSION['phone']<br>Mobile: $_SESSION['mobile']<br>E-mail: $_SESSION['email']<br>Web: $_SESSION['web']<br><hr><br>";

mysql_close($link);

?>
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — Also maybe you can explain this to me... On my page called membersarea.php this is the code.


<div id="usercontainer">

<FONT color=#f80000 size=4 face="customfont">

<?php

session_start();

if ($_SESSION['username'])

{

echo "You are logged in as ".$_
SESSION['username'];

echo "<p>";

echo "<a href='logout.php'>Click to logout</a> &nbsp; <a href='profile.php'>Edit Profile</a>";

}

else

header ("location: index.php");

?>

</font>

</div>


</body>

</html>

How does it know the session username with out me defining any variables on this page.

When I change the $_SESSION['username']; to $_SESSION['email']; I get a syntax error. How come it knows the username and works just fine on every page I include this file on but when I use email there instead it does not know it???
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — Sorry, my fault, I forgot to format the echo properly. It should be:
[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]
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — Firstly, your [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]

With regard to it not echoing out the email stored in the session, have you checked you are actually getting an email from the database and that it is being assigned correctly to the session variable:
[code=php]echo $row['email'];
var_dump($_SESSION); // to view all session data, or
var_dump($SESSION['email']) // to just view the email
[/code]
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — Thank you that fixed the echo... but now when i load the page I get this error

Notice: Undefined index: username in C:xampphtdocspixelprofile.php on line 60

Notice: Undefined index: password in C:xampphtdocspixelprofile.php on line 61

Notice: Use of undefined constant mysql_fetch_array - assumed 'mysql_fetch_array' in C:xampphtdocspixelprofile.php on line 65

these are 60 and 61

$username = mysql_real_escape_string(trim($_POST['username']));

$password = mysql_real_escape_string(trim($_
POST['password']));

This is 65

while ($row = mysql_fetch_array)($result);
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — The undefined index problem generally means that no information is being assigned to the variables, possible a problem with your posted data. Try echoing out the posted data to see if they have any values.

As for the while loop, what you have is incorrect but I also missed a closing bracket in my original code. It should be:
[code=php]while ($row = mysql_fetch_array($result)) {[/code]
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — First off thank you so much for all your help... You really are helping me understand a ton and I can tell that this is really close to working.. I am now getting these errors...

Notice: Undefined index: username in C:xampphtdocspixelprofile.php on line 60

Notice: Undefined index: password in C:xampphtdocspixelprofile.php on line 61

Notice: Undefined index: phone in C:xampphtdocspixelprofile.php on line 77

Notice: Undefined index: mobile in C:xampphtdocspixelprofile.php on line 77

Notice: Undefined index: email in C:xampphtdocspixelprofile.php on line 77

Notice: Undefined index: web in C:xampphtdocspixelprofile.php on line 77

This is line 77

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>";

I am pretty sure this is because I am not assigning the variables right when entering the data in to the DB.
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — That is what I said before, echo out the data you are fetching from your database to ensure you are getting it and the data is correct. So as a temporary measure, in your while loop, comment out assigning to the sessions and echo each row individually.
[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]

Run this and see if you have a value for the username and that it is correct. If so change the echo statement to the next value (in this case phone) and run again and so on.
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — I am assuming this is because I have a registration.php posting data in the data base and then assigning variables.

a login.php doing the same

and then we are working in a profile.php file currently.

So basically what I need to do is make sure the data when posted in the data base has a variable attached to each row.

Then when we log in make sure this information matches.

Then in the profile page in order to call this information make sure they are calling the right variables assigned in the previous files??? From what I am gathering this is how it works???

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???
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — Actually, looking at the code again, the problem is still your data being submitted by your form. What is you form code?
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — This is the register.php

<?php

$connect = mysql_connect("localhost","root","") or die ("Could not connect to databade.");

mysql_select_db("login") or die ("Could not find database.");




/* Now we will store the values submitted by form in variable */

$first=$_POST['first'];

$last=$_
POST['last'];

$phone=$_POST['phone'];

$mobile=$_
POST['mobile'];

$username=$_POST['username'];

$email=$_
POST['email'];

$web=$_POST['web'];

$password=$_
POST['password'];

$password1=$_POST['password1'];

/* Now we will check if username is already in use or not */

$queryusername=mysql_query("SELECT * FROM users WHERE username='$username' ");

$checkusername=mysql_num_rows($queryusername);

if($checkusername != 0)

{ echo "Sorry, ".$username." is already been taken."; }

else {

/* now we will check if password and confirm password matched */

if($password != $password1)

{ echo "Password and confirm password fields were not matched"; }

else {

/* Now we will write a query to insert user details into database */

$insert_users=mysql_query("INSERT INTO users (first, last, phone, mobile, username, email, web, password) VALUES ('$first', '$last', '$phone', '$mobile', '$username', '$email', '$web', '$password')");

if($insert_users)

{ echo "Registration Successful Please Login.<a href='access.php'>Redirecting to login page</a>";

header( "refresh:1;url=access.php" );

}

else

{ echo "error in registration".mysql_error();

header( "refresh:4;url=access.php" );

}

/* closing the if else statements */

}}

mysql_close();

?>



AND THIS IS THE LOGIN.PHP
<?php

session_start();

$username = $_POST['username'];

$password = $_
POST['password'];

if ($username&&$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='$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");


}

else

die ("Please enter a username and password");



?>
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — 
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]


No, you don't need to have already set up SESSION, that is what I have done in the while loop.

Once you have checked your data submitted from your form and obtained from the database (all code and options I have provided already), you can then dump the session (again as I have suggested earlier) to see if the data is being sotred in the session variables as it should.
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — You don't have a login form - you can't post data without a form to post it from. In fact I can't see a registration form either - where are your forms?
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — <html>

<form action="login.php" method="POST">

<p>Username: <input type="text" name="username"> <p>

<p>Password: <input type="password" name="password"> <p>

<input type="submit" name="submit" value="Login">

</form>


</html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>register</title>

</head>

<body bgcolor="black" style="color:white;">

<div id="headcontainer">

<div id="login">

<form method="post" action="register.php">

<table border="0">

<tr><td>First Name: </td><td><input type="text" name="first" /></td></tr>

<tr><td>Last Name: </td><td><input type="text" name="last" /></td></tr>

<tr><td>Phone: </td><td><input type="text" name="phone" /></td></tr>

<tr><td>Mobile: </td><td><input type="text" name="mobile" /></td></tr>

<tr><td>Username: </td><td><input type="text" name="username" /></td></tr>

<tr><td>Email: </td><td><input type="text" name="email" /></td></tr>

<tr><td>Website: </td><td><input type="text" name="web" /></td></tr>

<tr><td>Password: </td><td><input type="password" name="password" /></td></tr>

<tr><td>Confirm Password: </td><td><input type="password" name="password1" /></td></tr>

<tr><td></td><td><input type="submit" value="submit" /></td></tr>

</table>

</form>

</div>

</div>

</body>

</html>
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — OK, rather than this getting really messy, have you ehco'd out the data and dumped the session variables etc as I suggested?
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — I went through them and the only one I can get to show is this.


Notice: Undefined index: username in C:xampphtdocspixelprofile.php on line 61

Notice: Undefined index: password in C:xampphtdocspixelprofile.php on line 62

Notice: Undefined index: phone in C:xampphtdocspixelprofile.php on line 79

Notice: Undefined index: mobile in C:xampphtdocspixelprofile.php on line 79

Notice: Undefined index: email in C:xampphtdocspixelprofile.php on line 79

Notice: Undefined index: web in C:xampphtdocspixelprofile.php on line 79

Username: admin **************************

Phone:

Mobile:

E-mail:

Web:
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — OK, do the other fields in your database have values as it doesn't appear so?
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — after changing a bunch of stuff that I would of never understood to change if it was not for you... in the login.php file I have made it work!!!!!!!!!!!!!

But I have one more error that I can not seem to figure out...


Notice: Undefined index: username in C:xampphtdocspixelprofile.php on line 61

Notice: Undefined index: password in C:xampphtdocspixelprofile.php on line 62

these are 61 and 62

$username = mysql_real_escape_string(trim($_POST['username']));

$password = mysql_real_escape_string(trim($_
POST['password']));
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — That is odd as if you are getting the posted data through correctly then the variables should have the data. Can you try removing the mysql_real_escape_string so you are just left with [code=php]$username = trim($_POST['username']); // same for password[/code]
And see if you still get the error.

Also echo out [code=php]$username
// and
$password[/code]

And see what you get, then let me know.
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — nothing still get error.


Notice: Undefined index: username in C:xampphtdocspixelprofile.php on line 60

Notice: Undefined index: password in C:xampphtdocspixelprofile.php on line 61

Username: hahaha

Phone: 817-777-5125

Mobile: 817-235-2412

E-mail: hahaha@haha

Web: http://www.tattooworld.com
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — So when you try to echo out the username and password (by the way I missed out the echo in my previous code) you get nothing displayed?

Try this:
[code=php]if (isset($_POST['username'])) {
echo $_POST['username'];
} else {
echo 'No username posted';
}[/code]

And do the same for your password - let me know what you get.
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — ya but at the same time I am posting the username.. I just cant get it to work in that section of code.. here let me show you.

<?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());

$username = trim($_POST['username']); // same for password *******************************This line is not working

$password = trim($
_
POST['password']); // same for password *******************************This line is not working

$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 "$username"; *********************************when I add here is still does not post... BUT AS YOU SEE UNDER THIS LINE I HAVE A USERNAME POSTING WHILE ITS ATTATCHED TO SESSION

echo "$password";

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);

?>
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — This might help if you see what I fixed earlier in the login.php file to get us where we are...

<?php

session_start();

$username = $_POST['username'];

$password = $_
POST['password'];

if ($username&&$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='$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");


}

else

die ("Please enter a username and password");



?>
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — What I meant is this (though I don't know how your query is working if your username and password variables have no values):
[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]

This is just for testing you understand, to see if the data is being posted correctly.
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — You don't need to check the username in both your db query and with the results of that query. If you can test what I just posted I will sort the login script (give me 10 minutes or so)
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — This is what I get

No username postedNo password posted

Notice: Undefined variable: username in C:xampphtdocspixelprofile.php on line 71

Notice: Undefined variable: password in C:xampphtdocspixelprofile.php on line 71

Notice: Undefined variable: username in C:xampphtdocspixelprofile.php on line 83

Notice: Undefined variable: password in C:xampphtdocspixelprofile.php on line 84
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — There you have your answer then, what is the code for your login form (the form, not the php)?
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — Once your form is working as it should (will sort when you post the code) the the login script will be:
[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]
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — <html>

<form action="login.php" method="POST">

<p>Username: <input type="text" name="username"> <p>

<p>Password: <input type="password" name="password"> <p>

<input type="submit" name="submit" value="Login">

</form>


</html>
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — That is odd as your form looks fine and it is posting to the login page so I cannot see why the login page is not receiving the posted data.

Can you put [code=php]var_dump($_POST);[/code] at the top of your login page and post here exactly what you get back?
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — what do you mean what I get back?
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — If you dump the data you should see code at the top of the page - try it and see :-)
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — it shows the

session_start(); in the top left corner of the screen
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 26.2012 — I am sorry. I added the var dump to the top of the login.php page which is the page that executes when you click login button. and I dont see anything change.

When I add it to the profile page that all the code has been on I get this at the top left screen

array(0) { }
Copy linkTweet thisAlerts:
@simplypixieAug 26.2012 — You shouldn't be able to see the session_start() anywhere on the page, something is wrong with your code there.

Are you sure you have all your code in login.php (where the form submits to) not a different file?
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 27.2012 — i have fixed the session start issue it does show up in the page anymore. its now set up correctly. I have the code in the login.php set up the way you posted and it works fine. Now once you log in you are redirected to profile.php which is the code we have been echoing out the users information. that is where the errors are coming from.

profile.php

</div>

<div id="profilebio">

<p>This is where you write a bio about guess who? you!!!</p>

<?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());

$username = mysql_real_escape_string(trim($_POST['username'])); ************************************************The issues our on these two lines... ****************************************** line 59

$password = mysql_real_escape_string(trim($
_
POST['password'])); ************************************************The issues our on these two lines... ****************************************** line 60

$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);

?>

</div>

</div>

<div id="footer".

<?php include('footer.php'); ?>

</div>

</body>

</html>


<div id="footer".

<?php include('footer.php'); ?>

</div>


</body>

</html>

The session start is in the memberarea.php page which is included on this page.

And this is the output on the page


Notice: Undefined index: username in C:xampphtdocspixelprofile.php on line 59

Notice: Undefined index: password in C:xampphtdocspixelprofile.php on line 60

Username: hahaha

Phone: 817-777-5125

Mobile: 817-235-2412

E-mail: hahaha@haha

Web: http://www.tattooworld.com
Copy linkTweet thisAlerts:
@simplypixieAug 27.2012 — I am totally confused - your login form goes to login.php, not profile.php and that is where your login script should be.

Why do you have the same login code in profile.php?
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 27.2012 — hahahahah cause I am horrible man. and luckily because of your patience and skill its 100 percent fixed... ? thank you man. I wish there was some way i could repay you for all your time.. seriously your generosity is just amazing.

Thank you for everything.
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 27.2012 — Maybe you can tell me... from here on out I have lots of things to add should I start a new thread for each thing or just continue on here???
Copy linkTweet thisAlerts:
@Nicholas_DiazauthorAug 27.2012 — Now the information is displaying on the profile page correctly I need to add a button next to the information being echo that allows them to edit their information then resubmit it to the data base making the changes to the rows that it is stored in.
Copy linkTweet thisAlerts:
@simplypixieAug 27.2012 — No problem - I answer on forums to help in a way that I would like to have been helped when I started out.

I would start a new thread for each different problem as then it is easier for people to read the exact problem and answer without scrolling through all the posts from this thread. It also helps people searching to resolve their own problems.

However, in answer to your above question it will just be a basic form button which takes them to an edit_profile.php page (name it what you like) where there will be a form for them to change their details as required (similar to the registration form and php).
×

Success!

Help @Nicholas_Diaz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...