tecmeister Posted May 27, 2008 Share Posted May 27, 2008 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 Quote Link to comment Share on other sites More sharing options...
Gighalen Posted May 27, 2008 Share Posted May 27, 2008 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. Quote Link to comment Share on other sites More sharing options...
Gighalen Posted May 27, 2008 Share Posted May 27, 2008 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. Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 Just looking at the info that you have given me. Dont you need to state the server and database that you are getting it from? I was just wondering im a total nubetube to php. Quote Link to comment Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
Gighalen Posted May 28, 2008 Share Posted May 28, 2008 Yes, sorry. I assumed that since you already had a login system that you would have an included file that was always conected to the DB Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 Ok Thanks. I was just making sure. Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 When i enter the script that you have given me it is coming up with this error. Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/sites/nurevolution.co.uk/public_html/web_design/Members Page/profile.php on line 24 Quote Link to comment Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 echo "Username: ".data['username'];."<br>"; Should all be changed to this I believe. echo "Username: ".$data['username']."<br />"; Added a dollar sign in front of data and got rid of the first ; behind the field. Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 28, 2008 Share Posted May 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 28, 2008 Share Posted May 28, 2008 this is the problem. $sql is not defined: mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
Gighalen Posted May 28, 2008 Share Posted May 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 If i delete that then i get this: Username: Name: E-Mail: Company: Address 1: Address 2: City: County: Post Code: Phone Number: Mobile Number: I dont get the users info. I have know idea what else i need to do. Please help me. Quote Link to comment Share on other sites More sharing options...
Gighalen Posted May 28, 2008 Share Posted May 28, 2008 If your query is set up right... $id = $_GET['id']; $q = mysql_query("SELECT * FROM users WHERE id = '$id'"); $data = mysql_fetch_array($q); echo "Username: ".$data['username']; ^ Will display a username Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
Gighalen Posted May 28, 2008 Share Posted May 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 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? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 28, 2008 Share Posted May 28, 2008 Serious question: Do you have any idea as to how $_GET works? =X Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 28, 2008 Author Share Posted May 28, 2008 NO Im a nudetube to PHP and im trying learn. I just get stuff from tutorials Where can i start to learn PHP Quote Link to comment Share on other sites More sharing options...
tecmeister Posted May 29, 2008 Author Share Posted May 29, 2008 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. Quote Link to comment Share on other sites More sharing options...
peranha Posted May 29, 2008 Share Posted May 29, 2008 if you echo $id what do you get?? is it empty?? Also this $id = $_GET['id']; gets the id from the url as in www.somesite.com/page.php?id=12345 Quote Link to comment Share on other sites More sharing options...
Gighalen Posted May 29, 2008 Share Posted May 29, 2008 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'] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.