I am somewhat new to PHP coding but I have the basics down pretty good. I am just not sure on how to echo an image onto the page without getting SOME sort of error 🙁
My setup is that I go to an admin panel that I have set up, and when I upload an image along with a Name and Comment, it will appear on my achievements page in the order of Name, Picture(the image not link) , comment.
HTML Upload Form:
<code>
<form enctype="multipart/form-data" action="achievementUP.php" method="POST">
File Name: <input type="text" name="fileName"><br/>
Comment: <input type="text" name="fileComment"><br/>
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form></code>
Achievement Page PHP Code:
<code>
<div id="achievements">
<div id="achievements-head"><p class="heading">Achievements!</p></div>
<?php
mysql_connect("localhost", "username", "mypassword");
mysql_select_db("achievements");
$query = "SELECT * FROM pictures ORDER BY `id` ASC";
$result = mysql_query($query);
$pict = $row['pic'];
while ($row = mysql_fetch_array($result)) {
echo $row['name']."-".????. $pict . '">;
echo "<br/>";
}
?>
</div>
</code>
Achievement Uploading PHP Code:
<code>
<?php
// Where the file is going to be placed
$target_path = "images/achieve/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$target_path = "images/achieve/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded.";
} else{
echo "There was an error uploading the file, please try again!";
}
$con = mysql_connect("localhost","username","mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("achievements", $con);
$fileName = filter_input(INPUT_POST , "fileName");
$fileComment = filter_input(INPUT_POST, "fileComment");
$fileURL = $_FILES['file']['name'];
mysql_query("INSERT INTO pictures (id, name, pic, comment)
VALUES ('', '$fileName', '$fileURL', '$fileComment')");
echo 'Your File Has Been Uploaded. Return to <a href="https://localhost/stas9/index.php">main page</a>';
?>
</code>
Please help!