We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,987 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Display User details: from sql to dreamweaver

Hi, i have successfully made my registration and login page.

Now i need help.

When i click on login by using specific username and password that i had created, i want my next page to show details about that person, this details are stored in Mysql when they register and enter their information like age, company, address etc. I want this information to display when the user signs in with his/her username and i want something like a welcome label with their name on my page e.g. rob welcome to your profile so how can i actually get that name rob on my page without doing it manually and hence picking it up from my sql database?

After this i want them to edit this data and save it.

I tried going through many things but i was unable to do that, can anyone help: (i am using dreamweaver and php)?

Thank you

4
Contributors
40
Replies
1 Year
Discussion Span
7 Months Ago
Last Updated
48
Views
Question
Answered
Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I bet we could help, but you need to share your code. How far have you got?

If you just want somebody to write the think for you, try Google.

diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

Sir, what part of the codes do i show ?...
Below are the codes for the login button which will prompt me to another page, hence not showing details of that user (which i want and i do not know how to do).

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="cascadeglobal"; // Database name
$tbl_name="registration"; // Table name


mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];


$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);


$count=mysql_num_rows($result);


if($count==1){

session_register("myusername");
session_register("mypassword");
header("location:Index.html");

}
?>
}
else {
echo "Wrong username and password";
}
?>
Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Sir, what part of the codes do i show ?...

Well, the stuff you're struggling with! :)

Something like this? Not tested and only a bare bones idea. It's far from being a production example.

<?php
session_start();
if(!isset($_SESSION['login'])){
	$host="localhost"; // Host name
	$username="root"; // Mysql username
	$password=""; // Mysql password
	$db_name="cascadeglobal"; // Database name
	$tbl_name="registration"; // Table name
	 
	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");
	 
	$myusername = mysql_real_escape_string($_POST['myusername']);
	$mypassword = mysql_real_escape_string($_POST['mypassword']);
	 
	$result=mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'");
	 
	if(mysql_num_rows($result) == 1){
		$d = mysql_fetch_assoc($result);
		$_SESSION['login'] = $d['username'];
		//...add any other impt fields to $_SESSION array ...
		header("location: index.html");
		exit;	
	} else {
		$output = "Wrong username and password";
	}
}else{
	$output = "You're already logged in you dozy git";	
}

?>

You just echo the $output variable wherever you need it in the page. All the above code should be placed right at the top of the page - before the DTD (if you're using one).

diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

Still dont get it ... :|

Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Your index page could have this:

session_start();

if(isset($_SESSION['login']))echo $_SESSION['login'];

try it to see if it works

diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

Ok, i'll make it simple and clear hope its easy to understand.

I want a page on my dreamweaver that displays information that i had entered during the registration.

The data that should be displayed will depend on the username and password a person enters on his or her login page.

For example: i have a registration form which asks:
Enter First Name, Last Name, Age, Gender, Address, Email, User Name, Password and Confirm Password.
Once the user registers he or she is taken to the login page.
(I am using mysql to store all the information)
On the login page when they write their username and password on clicking signin i want another page that display:

Hi Username,
This is your profile,
First Name: aaa
Last Name: bbb
Age: ccc
Gender: ddd
Address: eee
Email: fff
User Name: ggg

Hope this is easy to understand.

I tried looking for tutorials and forums, but still couldn't find a solution to this.

Could you give a suggestion on what to do ? ...

Thank you

Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

THis is what I've been leading up to.

$d = mysql_fetch_assoc($result);
		$_SESSION['login'] = $d['username'];
		//...add any other impt fields to $_SESSION array ...
		header("location: index.html");

That bit of code put the DB info you want into the session array. Add your various fields, e.g.

$_SESSION['email'] = $d['email'];

etc.

Anyway, any page that needs to show the session data can do so:

session_start();
 
if(isset($_SESSION['login']))echo $_SESSION['login'];

Like that. Your request WAS easy to understand, but my replies obviously weren't. :(


You can modify it anyway you like:

session_start();
 
if(isset($_SESSION['login'])){
  echo "Hi {$_SESSION['login']}<br />
This is your profile,<br />
First Name: {$_SESSION['fname']}<br />
Last Name: {$_SESSION['lname']}<br />
Age: {$_SESSION['age']}<br />
Gender: {$_SESSION['gender']}<br />
Address: {$_SESSION['address']}<br />
Email: {$_SESSION['email']}<br />
User Name: {$_SESSION['username']}";
}
diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

Hi Ardav this is what i have done, but it doesn't display any information it says your details are not recorded:

<?php
//session_start();
//if(!session_is_registered(myusername)){
$username=$_POST['myusername'];
$password=$_POST['mypassword'];

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cascadeglobal", $con);
$result = mysql_query("SELECT * FROM registration WHERE username = '$username' AND password= '$password'");

while($row = mysql_fetch_array($result))
{
$firstname=$row['firstname'];
$lastname=$row['lastname'];
$age=$row['Age'];
$gender=$row['gender'];
$address=$row['address'];
$email=$row['email'];
$username=$row['username'];

$typeofbusiness=$row['typeofbusiness'];
$businessname=$row['businessname'];
$businesslocation=$row['businesslocation'];
$typesofservices=$row['typesofservices'];
}
if ($username) 
{

echo "$firstname";
echo "$lastname";
echo "$age";
echo "$gender";
echo "$address";
echo "$email";
echo "$username";
echo "$typeofbusiness";
echo "$businessname";
echo "$businesslocation";
echo "$typesofservices";

}
else
	{
		echo "Your details are not yet recorded";
		
	}
	
mysql_close($con);


?>

<html>
<body>
Login Successful

<p><a href="logout.php\">Click here to logout!</a></p>

</body>
</html>
Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

that just means that the sql didn't retrieve a record.

don't use 'while' if you're after one record - no need.

anyway

$username=$_POST['myusername'];
$password=$_POST['mypassword'];
...
$result = mysql_query("SELECT * FROM registration WHERE username = '$username' AND password= '$password'");
 
while($row = mysql_fetch_array($result))
{
...
$username=$row['username'];

These are your areas to check.

I would avoid using the same var name for $username from post and the one from the DB. You would get an 'username' whether there was one in the DB or not, so be careful.

diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

Hey hey before using your codes, i just tried out something and now i can see all my records that i had entered in my sql database.

Now i want only a specific row to appear, and that row will be identified by the username e.g. select * from registration where username.......i dont know what to write next

So heres my working code for displaying all information. :), how can i be able to display a record by username (i dont know if what am writing is clear enough or not sorry)

<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die('Could not connect: '.mysql_error());
}
mysql_select_db("cascadeglobal",$con);
$result =mysql_query("Select * from registration");
echo "<table border='1'>
<tr>
<th> First Name </th>
<th> Last Name </th>
<th> Age </th>
<th> Gender </th>
<th> Address </th>
<th> Email </th>
<th> Username </th>
<th> Type of Business </th>
<th> Business Name </th>
<th> Business Location </th>
<th> Types of Services </th>
</tr>";
while ($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" .$row['firstname'] ."</td>";
echo "<td>" .$row['lastname'] ."</td>";
echo "<td>" .$row['Age'] ."</td>";
echo "<td>" .$row['gender'] ."</td>";
echo "<td>" .$row['address'] ."</td>";
echo "<td>" .$row['email'] ."</td>";
echo "<td>" .$row['username'] ."</td>";
echo "<td>" .$row['typeofbusiness'] ."</td>";
echo "<td>" .$row['businessname'] ."</td>";
echo "<td>" .$row['businesslocation'] ."</td>";
echo "<td>" .$row['typesofservices'] ."</td>";

echo "</tr>";
}
echo "</table>";
mysql_close ($con);
?>

<html>
<body>
Login Successful

<p><a href="logout.php\">Click here to logout!</a></p>

</body>
</html>
Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
$result = mysql_query("SELECT * FROM registration WHERE username = '$username'");
$row = mysql_fetch_assoc($result);
diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

I tried that but it doesnt work ...no actually it works but gives empty row

Ok i tried something else out and it actually works but thats not what i want but here it is:

$result = mysql_query("Select * from registration where username = 'jolly'");

It actually displays information on that person

But when i change the ...username = '$username'"); it gives me an empty row.

Hope this is helpful, sorry if you dont understand it

What problem is causing the row to be empty ?...

Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This is because $username does not contain a value that is in the DB.

do

echo "Select * from registration where username = '$username'";

and you'll probably find that it's empty.

diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57


But when i change the ...username = '$username'"); it gives me an empty row.

I always use something like this, and it works!

$sql = "SELECT * FROM users WHERE username='{$username}' AND password='{$password}'";
Stefano Mtangoo
Senior Poster
3,731 posts since Jun 2007
Reputation Points: 462
Solved Threads: 396
Skill Endorsements: 0

YOu usually only need to brace out a variable if it's a keyed array.

eg

$sql = "SELECT * FROM users WHERE username='{$val[0]}' AND password='{$myarr['pw']}'";
diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

Hi sir, i know im irritating you very much. You must be hating me by know sorry :), but i just want to learn.

Ok i do have values in the username thing...and i tried the echo doesn't work still...is it possible that the id of my username could be having a wrong spelling or something like that...

Thank you

Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Still gives an empty row thats my code:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' .mysql_error());
}
mysql_select_db("cascadeglobal", $con);
$myusername=$_POST['myusername'];

$result = mysql_query("Select * from registration where username = '$myusername'");

echo "<table border='1'>
<tr>
<th> First Name </th>
<th> Last Name </th>
<th> Age </th>
<th> Gender </th>
<th> Address </th>
<th> Email </th>
<th> Username </th>
<th> Type of Business </th>
<th> Business Name </th>
<th> Business Location </th>
<th> Types of Services </th>
</tr>";
$row = mysql_fetch_array($result);
{
echo "<tr>";
echo "<td>" .$row['firstname'] ."</td>";
echo "<td>" .$row['lastname'] ."</td>";
echo "<td>" .$row['Age'] ."</td>";
echo "<td>" .$row['gender'] ."</td>";
echo "<td>" .$row['address'] ."</td>";
echo "<td>" .$row['email'] ."</td>";
echo "<td>" .$row['username'] ."</td>";
echo "<td>" .$row['typeofbusiness'] ."</td>";
echo "<td>" .$row['businessname'] ."</td>";
echo "<td>" .$row['businesslocation'] ."</td>";
echo "<td>" .$row['typesofservices'] ."</td>";

echo "</tr>";
}
echo "</table>";
mysql_close ($con);
?>

<html>
<body>
Login Successful

<p><a href="logout.php\">Click here to logout!</a></p>

</body>
</html>
Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Boss still gives an empty row

Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
$myusername=$_POST['myusername'];

you are posting data to it by form, I hope?

try this for now:

$myusername='jolly';

It should work. If it does, it's your form. Show the code for that.
Remember, you must have a name attribute of myusername:

<input type="text" name="myusername" />
diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1294 seconds using 2.81MB