| | |
Profile user page
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
0
#2 Oct 12th, 2009
Make a seperate page (profile.php perhaps) and use the unique field in the database (Usually an ID of some sort) in the query string, for example, profile.php?user=usersID.
In the profile.php page, pull the required data from the database and display it as required.
In the profile.php page, pull the required data from the database and display it as required.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
Join Date: Oct 2009
Posts: 50
Reputation:
Solved Threads: 0
0
#6 Oct 13th, 2009
I now how to echo id but how to echo username, email...
This is my code for profile page:
This is my code for profile page:
PHP Syntax (Toggle Plain Text)
<?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="login4"; // Database name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die(mysql_error()); mysql_select_db("$db_name")or die(mysql_error()); $id = $_GET['id']; $result = mysql_query("SELECT * FROM users WHERE id=$id"); $sql="SELECT * FROM users"; ?> <?php echo $id; ?>
•
•
Join Date: Oct 2009
Posts: 50
Reputation:
Solved Threads: 0
0
#7 Oct 13th, 2009
I now how to echo id but how to echo username, email...
This is my code for profile page:
This is my code for profile page:
PHP Syntax (Toggle Plain Text)
<?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="login4"; // Database name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die(mysql_error()); mysql_select_db("$db_name")or die(mysql_error()); $id = $_GET['id']; $result = mysql_query("SELECT * FROM users WHERE id=$id"); $sql="SELECT * FROM users"; ?> <?php echo $id; ?>
0
#8 Oct 13th, 2009
Many problems with your code there...
There appears to be no protection on your query at all...
Try replacing this:
with this:
Also, this line
Instead of this:
Try this I added a limit as I assume you will only be expecting one result:
You can then call the values from the DB using $result['field_name'].
So to review, your code should look similar to this:
Also, as ardav said, you will need to add some logic to make sure that the user viewing this page actually has permission to do so, such as creating a session when they login, and check that a session exists when they access this page
There appears to be no protection on your query at all...
Try replacing this:
PHP Syntax (Toggle Plain Text)
$id = $_GET['id'];
PHP Syntax (Toggle Plain Text)
if (is_int($_GET['id'])) { $id = $_GET['id']; // Add the rest of the script here. } else { // Display an error message, also stop processing. echo "Error message here"; }
Also, this line
$sql="SELECT * FROM users"; is redundant, it does nothing...Instead of this:
PHP Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM users WHERE id=$id");
PHP Syntax (Toggle Plain Text)
$query = mysql_query("SELECT * FROM users WHERE id=$id LIMIT 1"); $result = mysql_fetch_assoc( $query );
So to review, your code should look similar to this:
PHP Syntax (Toggle Plain Text)
<?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="login4"; // Database name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die(mysql_error()); mysql_select_db("$db_name")or die(mysql_error()); if (is_int($_GET['id'])) { $id = $_GET['id']; $query = mysql_query("SELECT * FROM users WHERE id=$id LIMIT 1"); $result = mysql_fetch_assoc( $query ); echo $id; } else { // Display an error message, also stop processing. echo "Error message here"; } ?>
Also, as ardav said, you will need to add some logic to make sure that the user viewing this page actually has permission to do so, such as creating a session when they login, and check that a session exists when they access this page
Last edited by Will Gresham; Oct 13th, 2009 at 5:28 pm.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
![]() |
Similar Threads
- Profile Viewing Page suggestions/ideas (DaniWeb Community Feedback)
- redirect user to another page if error 404 (ASP)
- How to refresh a page (PHP)
- How can i use php to create a members profile??? (PHP)
- How to create a members profile (PHP)
- Removing a PC from the Domain WITHOUT killing the user's profile (Windows NT / 2000 / XP)
- Login and retrieve user data from database (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: Echo a Variable
- Next Thread: passing varaible between pages ussing sessions
Views: 288 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date directory display download dynamic echo email error file files folder form format forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






