Jump to content

Users Profile


tecmeister

Recommended Posts

Hi,

 

I have finished creating the login and reister pages with help from you lot.

 

Now i would like the help with creating 'profile.php'.

 

On this page the user will be able to see their name address etc, be able to edit their password.

 

Is there a tutorial or any information you be able to give me that will help me create the page?

 

Thanks for all of the help that you have given me.

 

tecmeister

Link to comment
Share on other sites

Let's say your table for 'users' looks like this:

id
username
password
name
aim
yahoo
icq
website
address
email

 

Now, for a basic structure of your profile.php page, you would do something like so:

/*Retrieve the data*/
$id = $_GET['id'];
$q = mysql_query("SELECT * FROM users WHERE id = '$id'");
$data = mysql_fetch_array($q);
/*To display the data*/
echo "Username: ".data['username'];."<br>";
echo "Name: ".data['name'];."<br>";
echo "AIM: ".data['aim'];."<br>";
echo "Yahoo: ".data['yahoo'];."<br>";
echo "ICQ: ".data['icq'];."<br>";
echo "Website: ".data['website'];."<br>";
echo "Address: ".data['address'];."<br>";
echo "E-mail: ".data['email'];."<br>";

And so on. Now to view a profile, you would go to profile.php?id=x , with x being the id of the profile you wish to view.

Link to comment
Share on other sites

Ah, I didn't see that part about the edit password. I would assume you would have two files: profile.php and useredit.php.

 

The coding required for useredit is more than I feel like writing at the moment, but to change a password you need 3 text input fields: current password, new password, confirm new password. You would pass those three variables off to a process which will convert 'current password' to md5 (You ARE using md5, aren't you?), retrieve the users current password from the database, and compare them. If they are the same, it will convert the new password and confirm new password to md5 and compare those. If THEY match, you need simply to run a UPDATE query inserting the new password into the database.

 

Check out this tutorial http://evolt.org/node/60384 if you need help. It's pretty advanced, but if you can understand php-mysql to an extend, it's great. I just download the files and use them any time I need a login system - it's super uber easy to add new fields and it says A LOT of coding.

 

 

Link to comment
Share on other sites

Yes you would need to connect to the server and database

 

// open connection

$connection = mysql_connect("Server", "Username", "Password") or die ("Unable to connect!");

 

// select database

mysql_select_db("Database") or die ("Unable to select database!");

 

That will get you started.

 

replace Server, Username, Password, and Database to your credentials.

Link to comment
Share on other sites

Thanks alot the $ work.  But now i have a new problem/error

 

Once i had finished typing the script i got this error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/nurevolution.co.uk/public_html/web_design/Members Page/profile.php on line 22

Username: Name: E-Mail: Company: Address 1: Address 2: City: County: Post CodePhone NumberMobile Number

Link to comment
Share on other sites

that means your query failed. whenever you use mysql_query(), add or die(mysql_error()) to see what the error is, if any:

 

// ALWAYS
mysql_query($sql) or die(mysql_error());

 

otherwise you get that error and no clue what's wrong except something to do with mysql.

Link to comment
Share on other sites

Thanks alot.

 

It is now coming up with this error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/nurevolution.co.uk/public_html/web_design/Members Page/profile.php on line 22

Query was empty

 

This is the script that i have got on the page it i helps.

 


<?

$dbhost = "localhost";
$dbname = "********";
$dbuser = "********";
$dbpass = "********";

mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error());
mysql_select_db($dbname)or die(mysql_error());

/*Retrieve the data*/
$id = $_GET['id'];
$q = mysql_query("SELECT * FROM users WHERE id = '$id'");
$data = mysql_fetch_array($q);
mysql_query($sql) or die(mysql_error());
/*To display the data*/
echo "Username: ".$data['username'];
echo "Name: ".$data['name'];
echo "E-Mail: ".$data['email'];
echo "Company: ".$data['Company'];
echo "Address 1: ".$data['address1'];
echo "Address 2: ".$data['address2'];
echo "City: ".$data['city'];
echo "County: ".$data['email'];
echo "Post Code".$data['postal'];
echo "Phone Number".$data['phonenumber'];
echo "Mobile Number".$data['mobilenumber'];

?>

 

Also this is the script that i have got on the checkregister.php if it help

 


<?PHP

$dbhost = "localhost";
$dbname = ********;
$dbuser = ********;
$dbpass = ********;

mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error());
mysql_select_db($dbname)or die(mysql_error());



$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$company = $_POST['company'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$county = $_POST['county'];
$postal = $_POST['postal'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$mobile = $_POST['mobile'];



$checkuser = mysql_query("SELECT username FROM members Where username='$username'");

$username_exist = mysql_num_rows($checkuser);

if($username_exist >0){
echo "I'm sorry but the username that you specified has already been taken.  Please pick another one.";
unset($username);
include 'register.html';
exit();
}

$query = "INSERT INTO members (name,email,username,password,company,address1,address2,city,county,postal,country,phonenumber,mobilenumber)
VALUES('$name','$email','$username','$password','$company','$address1','$address2','$city','$county','$postal','$country','$phone','$mobile')";
mysql_query($query)or die(mysql_error());
mysql_close();

$yoursite = 'www.nurevolution.co.uk';
$webmaster = 'Johnny McCaffery';
$youremail = 'support@nurevolution.co.uk';

$subject = "You have successfully registered at $yoursite...";
$message = "Dear $name, you are now registered at our web site.  
    To login, simply go to our web page and enter in the following details in the login form:

    Username: $username
    Password: $password
    
    Please print this information out and store it for future reference.
    
    Thanks,
    $webmaster";
    
mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

echo "You have successfully Registered.";
    
echo "Your information has been mailed to your email address.";

?>

 

Thanks for all of the help that everyone has given me.

Link to comment
Share on other sites

I have changed the red text:

 

$id = $_GET['id'];

$q = mysql_query("SELECT * FROM members WHERE id = '$id'");

$data = mysql_fetch_array($q);

mysql_query($id) or die(mysql_error());

 

Now im getting:

 

Query was empty

 

Sorry for all this but i have know idea on what that means.

All of the php that i have got are from tutorials or what other people have told me to use.

 

I really need to start to learn php

 

From the info that i have given.  Is most of it right to create profile.php.  And what do i need to do to correct it.

Link to comment
Share on other sites

I don't even think you need this line:

mysql_query($sql) or die(mysql_error());

 

You're already sending $q through a query via mysql_query("SELECT * FROM");, so there should be no need to have that line. Try deleting it and see if that works.

Link to comment
Share on other sites

This is the script that im using:

 


/*Retrieve the data*/
$id = $_GET['id'];
$q = mysql_query("SELECT * FROM members WHERE id = '$id'");
$data = mysql_fetch_array($q);
/*To display the data*/
echo "Username: ".$data['username'];"<br>";
echo "Name: ".$data['name'];"<br>";
echo "E-Mail: ".$data['email'];"<br>";
echo "Company: ".$data['company'];"<br>";
echo "Address 1: ".$data['address1'];"<br>";
echo "Address 2: ".$data['address2'];"<br>";
echo "City: ".$data['city'];"<br>";
echo "County: ".$data['email'];"<br>";
echo "Post Code: ".$data['postal'];"<br>";
echo "Phone Number: ".$data['phonenumber'];"<br>";
echo "Mobile Number: ".$data['mobilenumber'];"<br>";

?>

 

And im not getting the users info.

 

Is there something that im missing.

Link to comment
Share on other sites

It looks good to me, and you said I was echoing out the text, just not the variables, I would assume it's with your query. Try replacing $id with a number in the database that you know exists, just to make sure you have your query set up right. If that works, I would assume that you $id variable isnt passing off correctly, which everything looks correct so I would assume it's just the way you have your query set up.

Link to comment
Share on other sites

I have tried to use:

 

$main = $_GET['1'];

$q = mysql_query("SELECT * FROM members WHERE 1 = '$main'");

$data = mysql_fetch_array($q);

 

I put the number there but i think it be abit wrong but im getting the thing:

 

Username: Name: E-Mail: Company: Address 1: Address 2: City: County: Post Code: Phone Number: Mobile Number:

 

Do i need to do a session or something?

Link to comment
Share on other sites

Hello,

 

I still seem to have the same problem.

 

Here is the script that i am using:


<?

$dbhost = "localhost";
$dbname = ********";
$dbuser = "********";
$dbpass = "********";

mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error());
mysql_select_db($dbname)or die(mysql_error());

/*Retrieve the data*/
$id = $_GET['id'];
$q = mysql_query("SELECT * FROM members WHERE 1 id = '$id'");
$data = mysql_fetch_array($q);
/*To display the data*/
echo "Username: ".$data['username'];
echo "<br>";
echo "Name: ".$data['name'];
echo "<br>";
echo "E-Mail: ".$data['email'];
echo "<br>";
echo "Company: ".$data['company'];
echo "<br>";
echo "Address 1: ".$data['address1'];
echo "<br>";
echo "Address 2: ".$data['address2'];
echo "<br>";
echo "City: ".$data['city'];
echo "<br>";
echo "County: ".$data['email'];
echo "<br>";
echo "Post Code: ".$data['postal'];
echo "<br>";
echo "Phone Number: ".$data['phonenumber'];
echo "<br>";
echo "Mobile Number: ".$data['mobilenumber'];
echo "<br>";

?>

 

From the script that you can see, how does it connect to the correct user.

 

Is there something that i need to type on the index of the members page?

 

Please can you help me.

Link to comment
Share on other sites

NO

 

Im a nudetube to PHP and im trying learn.

 

I just get stuff from tutorials

 

Where can i start to learn PHP

 

http://w3schools.com is THE best site to learn pretty much any web-developing language. I use it all the time for a quick-reference.

 

 

But as peranha previously stated, when you call a $_GET function, you are getting the variable from the url. If you are currently using a form and passing the variable off that way, you want to set your variable equal to $_POST['id']

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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