I'm sorry, I know that there are tons of image upload posts on here and I do believe I've been through them all and it got me this far but now I've been stuck for ages.
I have a site that allows users to submit a profile picture. If they don't choose one then a default pic is used (nopic.jpg). If they go to the profile update page then all of their fields are populated from mysql.
My best attempt was to use a hidden field called hiddenImage on the update page:
Some of the update page code:
$getInfo = "SELECT message, image from page WHERE loginName = '$loginName'";
$rs = mysql_query($getInfo, $conn) or die(mysql_error());$row = mysql_fetch_assoc($rs);
$image = $row['image'];
And later on the update page I have:
<input type="hidden" name="hiddenImage" value="<?php echo $image ?> "/>
Then on the action page I have this:
if (isset($_POST['SubmitBandpage'])) {
$image = "nopic.jpg";
$imagech = "{$_POST['hiddenImage']}";
$please = "Please use your browser's back button to correct the error.<br>";
if (is_uploaded_file($_FILES['image']['tmp_name'])) {
move_uploaded_file($_FILES['image']['tmp_name'], "./bandpics/".stripslashes($bandName).$_FILES['image']['name']);
$isize = $_FILES['image']['size'];
$type = $_FILES['image']['type'];
$image = $_FILES['image']['name'];
$image = $bandName.$image;
if ($type != "image/gif" && $type != "image/pjpeg" && $type != "image/x-png" && $type !="image/jpeg") {
$error= "Sorry, the acceptable formats for pictures are gif, jpeg, and png.<br>
$please";
include ('errorinc.php');
exit();
}
elseif ($isize >= 102400){
$error = "The maximum picture size is 100k.<br>
$please";
include ('errorinc.php');
exit();
}}
else{
if ($imagech != "" && $imagech != "nopic.jpg"){
$image = $imagech;
}}
Then I insert the $image variable into DB.
As it sits now, if somebody uploads a pic it works fine. If they go back to the update page and don't submit an image again it will keep the old one which is what I want. The only prob is that if a pic isnt uploaded then the nopic.jpg isnt sent to the DB. I tried moving one of the the closing "}" from after the "elseif ($isize >= 102400)"-statement to after the "if imagech.." statement and then it would enter the nopic.jpeg. But if people updated the page after that, then went back, it wont keep the saved image.
Is this the correct way to check if a value is not null?:
if(if ($imagech != "") ?
If anybody has a clue as to what in tarnation I've done here that would be great. I obviously need some help. Thanks alot.