ChidoriSoul Posted June 11, 2009 Share Posted June 11, 2009 Ok, so I am trying to create a user profile, so I want it to show the user's name, and I was wondering how to get that from the table that was used for Register, and then write the ID for it.Thanks!Shadow Link to comment Share on other sites More sharing options...
smerny Posted June 11, 2009 Share Posted June 11, 2009 Are you saying you want a form in register.php to put information into a mysql table?or that you want another form to pull information from the mysql table and put information into a different mysql table? Link to comment Share on other sites More sharing options...
ChidoriSoul Posted June 11, 2009 Author Share Posted June 11, 2009 I am trying to make like a User Profile like this:Name: It automatically gets thereID: etc:I want to know when a users registers, a page gets added with all of the information, and it will stay there. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 11, 2009 Share Posted June 11, 2009 You don't make a new page when they register, you just have one PHP profile page where you tell it which user to get the profile for. e.g.:profile.php?userid=10The page looks up that user's information and displays the information where you want it.Or, if they're logged in and you're using the session to keep track of who is logged in, you can also just have the profile page check the session to get the user ID instead of sending it in the URL. That's how they do it in this forum, since the session tracks who's logged in the link to the "My Controls" page is this:http://w3schools.invisionzone.com/index.ph...rCP&CODE=00It doesn't say which user it is, it gets that from the session. Link to comment Share on other sites More sharing options...
ChidoriSoul Posted June 11, 2009 Author Share Posted June 11, 2009 I would want the first option:profile.php?userid=1Now, how would I want to know how to create the page for each user when there is a new ID added Link to comment Share on other sites More sharing options...
smerny Posted June 12, 2009 Share Posted June 12, 2009 you don't need to create a new page, you will have one page that will display information from the database based on the ID.if you get to a page with "profile.php?userid=1", $_GET['userid] has a value of 1.then have your php take information from the row in the database table where userid is equal to $_GET['userid'] Link to comment Share on other sites More sharing options...
ChidoriSoul Posted June 12, 2009 Author Share Posted June 12, 2009 ok, so how can I have the DB read the information from the Register table, is I am correct. Link to comment Share on other sites More sharing options...
ChidoriSoul Posted June 12, 2009 Author Share Posted June 12, 2009 ok, so how can I have the DB read the information from the Register table, is I am correct. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 12, 2009 Share Posted June 12, 2009 The same way you do with any other database work, just connect to the database and send a query. The ID you get from the URL will go into the WHERE clause of the query. Link to comment Share on other sites More sharing options...
ChidoriSoul Posted June 12, 2009 Author Share Posted June 12, 2009 Ok, so would I use the Select ID from the MySQL Database, then use the Get Method to display it in the link? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 12, 2009 Share Posted June 12, 2009 Something like that. Link to comment Share on other sites More sharing options...
ChidoriSoul Posted June 21, 2009 Author Share Posted June 21, 2009 So, what is wrong with this linkMy PageMy code for the page is <?php// Connects to your Databasemysql_connect("fdb1.awardspace.com", "chidorisoul_sh", "******") or die(mysql_error());mysql_select_db("chidorisoul_sh") or die(mysql_error());$CheckAmountOfUsers = mysql_query("SELECT * FROM `users`, $con);$AmountOfUsers = mysql_num_rows($CheckAmountOfUsers);$i = 1;while($i >= $AmountOfUsers) {$GetUserInfo = mysql_query('SELECT * FROM `user` WHERE `ID` = ''.$i.''", $con);$UserInfo = mysql_fetch_array($GetUserInfo);echo "<a href=\'view_profile.php?user_id='.$i.'\'>".$UserInfo["Username"]."</a><br />";$i++;}GET["ID"]."'", $con);$array = mysql_fetch_array($query);$Username = $array["username"];<!--stuff-->$query = mysql_query("SELECT * FROM `users` WHERE `ID` = '". ?> Link to comment Share on other sites More sharing options...
Synook Posted June 21, 2009 Share Posted June 21, 2009 echo "<a href=\'view_profile.php?user_id='.$i.'\'>".$UserInfo["Username"]."</a><br />"; Count your quotes.Also this line is a bit random:GET["ID"]."'", $con); Link to comment Share on other sites More sharing options...
ChidoriSoul Posted June 22, 2009 Author Share Posted June 22, 2009 I fixed it for Quote CountThat line is for displaying data read of the table, for the iner depth of the profile. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 22, 2009 Share Posted June 22, 2009 That's not using the database efficiently. First you select all data from the users table, then count how many there are, then start a counter and select each user again individually. So you're sending 1 query per user, in addition to the one to get everyone. You're assuming that the IDs are numbered sequentially because you're printing the value of the counter for the ID instead of the actual ID from their user row, but what happens if you delete a user and remove that ID? The numbering will get messed up. You should only select the user data once, select the username and ID (or other fields if you need them, not necessary to select *), and then loop through the users and print each one out. It seems kind of strange to select everything, get the count, and then loop through and select each user again, and print the counter for the ID when you could just print the ID itself. You've got other problems with the while loop, but those will go away if you change how you're doing it. Link to comment Share on other sites More sharing options...
MrFish Posted June 23, 2009 Share Posted June 23, 2009 When a user registers it needs to create a user profile page and have his id attached to it, then when you go to the page it takes that id and retrieves all the information that is related to that id.Understand? Link to comment Share on other sites More sharing options...
duncan_cowan Posted June 23, 2009 Share Posted June 23, 2009 Forgive me if i'm wrong but i think a simple mysql select query would suffice:say the page is "yourpage.com?id=10" <?php// Connects to your Databasemysql_connect("fdb1.awardspace.com", "chidorisoul_sh", "******") or die(mysql_error());mysql_select_db("chidorisoul_sh") or die(mysql_error());$selectUser = mysql_query("SELECT * FROM users WHERE id = '" . $_GET['id'] . "' ");$user = mysql_fetch_array($selectUser);$username = $user['username'];//etc?> Hope this helps Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.