Changed php code but still have question

thenewprogrammer

New Member
Messages
45
Reaction score
0
Points
0
Having problems outputing information from a table called login. Database information is correct and users are in there under field 'username' .Noticed everyone's opinions on whats wrong with code havnt worked so far. Output is always User profile which is direct text in the head. When signed in. Since im new to php and dont understand everything wondering if the username has to be in the url for this to work? The username when i log in at first puts the username in the url for main page. But when i clicked profile the username isnt in the url anymore. Does it have to be in the url for this to work? if so how do i do it for this page.


Code:
<? 
$user = $_GET['user']; 
session_start(); 
 
if(!isset($_SESSION['user'])){ 
header("Location: http://thenewprogrammer.x10hosting.com");
} 
 
$dbhost = "localhost"; 
$dbname = "*****"; 
$dbuser = "*****"; 
$dbpass = "*****"; 
 
mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not connect: ".mysql_error()); 
mysql_select_db($dbname) or die("Could not select the database: ".mysql_error());
$username = mysql_real_escape_string($user);
$query = "SELECT * FROM login WHERE username ='".$username."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
?>
<html>
<head>
User Profile
</head>
<body>
<?php echo($username); ?>
<br />
<?php print_r($row); ?>
</body>
</html>
 

nexhunter

New Member
Messages
239
Reaction score
1
Points
0
?user=username should be at the end of the url to grab the data or you could use an if statement to grab the profile of the user viewing the profiles page or if the url is set grab that users data
PHP:
if(isset($_GET['user'])){
$user = mysql_real_escape_string( $_GET['user']); }
else{
$user = $_SESSION['user'];}
 
Last edited:

zapzack

New Member
Messages
606
Reaction score
19
Points
0
Erm... 404 = not found.. make sure it uploaded in the correct place And remove that if that the user above posted.. It would be a security vulnerability..
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
added the if statement and changed url but it gives me the 404 error

Please post the url you are using to access the script.

Also,

Code:
<head>
User Profile
</head>

is bad HTML.

Code:
<head>
<title>
User Profile
</title>
</head>

if you want it to be the title of the page, but not show up in the body.
 
Top