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

Member Avatar for diafol

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.

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";
}
?>
Member Avatar for diafol
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).

Still dont get it ... :|

Member Avatar for diafol

Your index page could have this:

session_start();

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

try it to see if it works

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

Member Avatar for diafol

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']}";
}

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>
Member Avatar for diafol

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.

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>
Member Avatar for diafol
$result = mysql_query("SELECT * FROM registration WHERE username = '$username'");
$row = mysql_fetch_assoc($result);

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 ?...

Member Avatar for diafol

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.


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}'";
Member Avatar for diafol

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']}'";
commented: I didnt knew that! Thanks! +13

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

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>

Boss still gives an empty row

Member Avatar for diafol
$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" />

When i write something like this:

select * from registration where username='jolly';

it works, but if i write the way u said

select * from $username ='jolly';

it doesnt work.

And yups have i have the type...= myusername


AND the way i use those previous code posted and the row is still empty this is how it looks:
http://jollymixer.webs.com/apps/photos/photo?photoid=128570547

Member Avatar for diafol
select * from $username ='jolly';

I never said that.
This is what I was referring to:

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

Okies, tried it still gives an empty row...

Member Avatar for diafol

OK, let me get this right...

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

works, but

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

doesn't?

SORRY SORRY, it is working both ways.

Member Avatar for diafol

Well, you can try evstevemd's suggestion:

$myusername='jolly';
echo "NO BRACE: Select * from registration where username = '$myusername'<br />BRACES: Select * from registration where username = '{$myusername}'"

Just to see if the query is empty or not

Hey wait wait, it was working both ways, but let me try the thing u told me to do.
The brace thing you just gave doesnt work either.

Hi now i can see the row, but everything is empty but i can see my age and address it shows 0(zero).

Member Avatar for diafol

I don't understand this.

$myusername='jolly';
$result = mysql_query("Select * from registration where username = '$myusername'");
//doesn't work
$myusername='jolly';
$result = mysql_query("Select * from registration where username = '{$myusername}'");
//doesn't work
$result = mysql_query("Select * from registration where username = 'jolly'");
//works

That doesn't make any sense. Post code that works and code that doesn't (both in full).

This codes do not show the details that i want, they take me to the next page where the table is but the row is empty.

<?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>

This codes show me the details about the username jolly

<?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 = 'jolly'");

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>

******And all this you showed are now working

$myusername='jolly';
$result = mysql_query("Select * from registration where username = '$myusername'");
//doesn't work
$myusername='jolly';
$result = mysql_query("Select * from registration where username = '{$myusername}'");
//doesn't work
$result = mysql_query("Select * from registration where username = 'jolly'");
//works

**********

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.