Hello. First off, i'm a beginner to PHP, but I'm getting into it, and would appreciate a little help. Here's what I want to do. I've got a webpage that has user profile information, and it is pretty much finished except for the fact that I want to allow the user to add a picture of themselves in their profile page. I have 2 documents, one that is the main page, called My_Files.php, and it is used for uploading the files. It works fine for uploading the information to my webserver, however, once there, I need for the image to be stored inside the user's profile independently, so if that requires that I also store the image inside of my mysql table, called USER, then that is fine. This document looks like the following:
<<<<<My_Files.php>>>>>>
<html>
<head>
<title>My Files</title>
<link rel="Stylesheet" type="text/css" href="CS170/Stylesheet2.cs
s">
</head>
<body>
<form enctype="multipart/form-da
ta" action="b.php" method="POST">
<table border="0" height="96%" width="89%" id="table1">
<tr>
<td width="65%">
<?php
$email = $_POST['email'];
$username = $_POST['username'];
$plaintext = $_POST['password'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$profileimage = $_POST['profileimage'];
$education_level = $_POST['education_level'];
$company = $_POST['company'];
$jobtitle = $_POST['jobtitle'];
$street = $_POST['street'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$birthday = $_POST['birthday'];
$website = $_POST['website'];
$phone = $_POST['phone'];
$aboutme = $_POST['aboutme'];
$resume = $_POST['resume'];
$ciphertext = md5($plaintext);
$rv = mysql_connect("localhost",
"USERNAME"
,"PASSWORD
");
mysql_select_db("DATABASEN
AME");
$qs = "select * from USER where username='$username';";
$result = mysql_query($qs);
$nrows = mysql_numrows($result);
$query = mysql_query($qs);
while ($row = mysql_fetch_array($query))
if($nrows == 1)
{
$dbpass = mysql_result($result, 0, "password");
{
}
$dbpass = mysql_result($result, 0, "password");
$dbpass = mysql_result($result, 0, "password");
if($dbpass == $ciphertext)
{
echo "<h1> " ."Welcome " . $username . "!" . "</h1> " . "\n";
printf("<img border='0' src='Images\Profiles\NoIma
ge.gif'>\n
");
printf("<input type='hidden' name='MAX_FILE_SIZE' value='100000'>\n");
echo "<h2>" . "Upload a Profile Picture: " . "</h2>" . "\n";
printf("<input name='file' type='file'>\n");
printf("<input type='submit' value='Add Picture'>\n");
echo "<br>" . "\n";
echo "<br>" . "\n";
echo "<h2> " ,$row['fname'] ." " . $row['lname'] . "<br> " . "Email: " ,$row['email'] . "</h2> " . "\n";
echo "<h3> " ."Other Information";
echo "<h4> " ."Name: " .$row['fname'] ." " . $row['lname'] . "<br> " . "Education Level: " .$row['education_level'] . "<br> " . "Current Employer: " .$row['company'] . "<br> " . "Job Title: " .$row['jobtitle']. "<br> " . "Address: " .$row['street'] . "<br> " . "City: " .$row['city'] . "<br> " . "State: " .$row['state'] . "<br> " . "Zip Code: " .$row['zip'] . "<br> " . "Birthday: " .$row['birthday'] . "<br> " . "Website: " .$row['website'] . "<br> " . "Phone Number: " .$row['phone'] . "</h4> " . "\n";
echo "<h3> " ."My Background " . "</h3> " . "\n";
echo "<h4> " .$row['aboutme'] . "</h4> " . "\n";
echo "<h3> " . "Skills" . "</h3>" . "<br> " . "<h4> " .$row['resume'] . "</h4>" . "\n";
printf("<input type='hidden' name='email' value='$email'>\n");
printf("<input type='hidden' name='username' value='$name'>\n");
printf("<input type='hidden' name='password' value='$ciphertext'>\n");
printf("<input type='hidden' name='fname' value='$fname'>\n");
printf("<input type='hidden' name='lname' value='$lname'>\n");
printf("</form>\n");
}
else
{
printf("<h1>Password incorrect.</h1><br><br><br
><br><br><
br>\n");
}
}
else
{
printf("<h1>Invalid name: %s</h1>\n",$username);
}
mysql_close();
?>
<td width="40%"></td>
</tr>
</form>
</table>
</body>
</html>
While b.php is the document that processes when they attempt to upload the information. It looks as follows:
<<<<<<<<b.php>>>>>>>>
<?php
$username = $_POST['username'];
$profileimage = $_POST['profileimage'];
mysql_connect("localhost",
"USERNAME"
,"PASSWORD
");
mysql_select_db("DATABASE"
);
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 100000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
if (file_exists("FILEPATHNAME
CHANGED" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES
["file"]["
tmp_name"]
,
"/FILEPATHNAMECHANGED" . $_FILES["file"]["name"]);
}
}
}
else
{
echo "Invalid file";
}
?>
My question is, how would I use this to display the image that is uploaded onto My_Files.php when it is next loaded? If I need to use a sql statement to pull info that's fine, but I'm a little lost. Help please!!!
Start Free Trial