PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
/**
* UserInfo.php
*
* This page is for users to view their account information
* with a link added for them to edit the information.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 2, 2009 by Ivan Novak
*/
include("include/session.php");
$page = "profile.php";
?>
<!DOCTYPE html>
<html lang="en-GB">
<head>
<title>Tag Texter | Homepage</title>
<link rel="stylesheet" href="style.css" type="text/css" />>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<div id="content_top_topimage"></div>
<div id="content_top">
<?php
/* Requested Username error checking */
$req_user = trim($_GET['user']);
if(!$req_user || strlen($req_user) == 0 ||
!eregi("^([0-9a-z])+$", $req_user) ||
!$database->usernameTaken($req_user)){
die("Username not registered");
}
/* Logged in user viewing own account */
if(strcmp($session->username,$req_user) == 0){
echo "<h1>My Account</h1><p>
<p>
<form name='newad' method='post' enctype='multipart/form-data' action='upload.php'>
<table>
<tr><td><input type='file' name='image'></td></tr>
<tr><td><input name='Submit' type='submit' value='Upload image'></td></tr>
<input type='hidden' name='username' value='$session->username' />
<br /><label>Profile?</label><input name='profile' type='checkbox' value='yes' checked>
</table>
</form>";
}
/* Visitor not viewing own account */
else{ ?>
<div id="profile_title">User Profile</div>
<?php
}
/* Display requested user information */
$req_user_info = $database->getUserInfo($req_user);
/* Name */
echo "<p><b>Name:</b> ".$req_user_info['name']."<br />";
/* Username */
echo "<p><b>Username:</b> ".$req_user_info['username']."<br />";
/**
* Note: when you add your own fields to the users table
* to hold more information, like homepage, location, etc.
* they can be easily accessed by the user info array.
*
* $session->user_info['location']; (for logged in users)
*
* ..and for this page,
*
* $req_user_info['location']; (for any user)
*/
/* If logged in user viewing own account, give link to edit */
if(strcmp($session->username,$req_user) == 0){
echo "[<a href=\"useredit.php\">Edit Account Information</a>]<br><br>";
}
/* Link back to main */
echo "[<a href=\"main.php\">Main</a>] ";
if($session->isAdmin()){
echo "[<a href=\"admin/admin.php\">Admin Center</a>] ";
}
?>
</div>
<div id="content_top_bottomimage"></div>
</body>
</html>
No matter what I do, I cannot get the picture (which has the path stored in a MySQL database) to show up. What do I do? Here is the table structure:
CREATE TABLE IF NOT EXISTS `uploads` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(30) NOT NULL,
`type` varchar(30) NOT NULL,
`size` int(11) NOT NULL,
`path` varchar(60) NOT NULL,
`username` varchar(100) NOT NULL,
`profile` varchar(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
I can't see your code for querying the database (to fetch the img path) nor can I see the code where you output that image - so it's hard to say what's going wrong right now - can you provide a bit more information?
Or are you asking us how you should go about querying the db and handling the result?
<?php
include('include/connect.php');
$term = $session->username;
$sql = mysql_query("select * from uploads where username like '$term'");
while ($row = mysql_fetch_array($sql)){
?>
<img src="http://tagtexter.com/tag/<?php echo ''.$row['path'];?>">
<?php
}
?>
If I use this on its own in a separate page, then it works just fine. However, when I try to put it into the other page I posted, nothing happens. Im not sure where on the page I would have to put the code in order for it to always show up. The point is that this is a profile picture, and I need it to show up on the users profile page (which I previously posted a copy of)
/* Display requested user information */
$req_user_info = $database->getUserInfo($req_user);
/* Name */
echo "<p><b>Name:</b> ".$req_user_info['name']."<br />";
/* Username */
echo "<p><b>Username:</b> ".$req_user_info['username']."<br />";
$term = $req_user_info['username'];
$sql = mysql_query("select * from uploads where username = $term");
while ($row = mysql_fetch_array($sql)){
?>
<?php echo $req_user_info['username']; ?>
<img src="http://tagtexter.com/tag/<?php echo ''.$row['path'];?>">
<?php
}
?>
<?php
that is returning a "mysql_fetch_array(): supplied argument is not a valid MySQL result resource" error. But, if I change the $sql to: "select * from uploads where id=2" (the id of a picture I know to be in the database) it shows the picture exactly how its supposed to.
What am I doing wrong?