I am having a terrible time trying to figure out why my picture files aren't uploading and MySql UPDATES not updating the picture link.
First I have narrowed it down by placing echo statements in the code to the point my echo doesn't show up any more and that is at the file upload part.
Second the html in the form is strange to me becuase of the .($add ? <html here> ): more html here.
It seems strange to have the input type=file part twice but this is a copy of the file upload that works in a "addPrize.php" file. This one is the "editPrize.php". In the addPrize.php it works because before hand the row is created without the picturelink and then when it gets to this part it just uses the UPDATE statement.
I've checked to make sure the prizeid in my UPDATE statement is right by echoing it out before this runs and then manually did the update in phpMyAdmin with no problem.
Code: Select all
echo 'test before file if statement'; //this one shows up meaning we're good so far
if((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/png") )
&& ($_FILES["file"]["size"] < 512000)) //500kb size limit
{
echo 'test after files if';//this one doesn't show, something is going wrong
$picturelink = $_FILES["file"]["name"];
$ext = pathinfo($picturelink);
$picturelink = 'prize_' . $_POST['prizeid'] . '_' . rand(0,300) . '.' . $ext['extension'];
if (file_exists("media/" . $picturelink))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"media/" . $picturelink);
//echo "Stored in: " . "media/" . $_FILES["file"]["name"];
}
/*$sql = "UPDATE Prizes SET picturelink ='media/".$picturelink."' WHERE prizeid = " . $_POST['prizeid'];*/
$sql = "UPDATE Prizes SET picturelink = 'media/'".$picturelink."'WHERE prizeid ='".$_POST['prizeid']."';";
echo '<!-- ' . $sql . ' -->';
mysql_query($sql)or die(mysql_error(). " : ".$sql);
echo "<h2>Success!</h2><br />Prize successfully edited!<br />";
}
Code: Select all
<td>'.($add ? '<input type="checkbox" id="picture" name="picture" value="'.$picturelink.'" checked="checked" />Use <a href="'.$picturelink.'" target="_blank" style="color:#000000;">Existing Picture</a><br /><input type="file" id="file" name="file" style="display:none" />' : '<input type="file" name="file" />').'