Jump to content

Archived

This topic is now archived and is closed to further replies.

Adastra

What's wrong with this upload?

Recommended Posts

Hi folks,
I have a form for updating an entry in a database, which is pretty much the same as my form for posting into the database, with the difference that this one isn't working.

Can anyone help me find out what's wrong? I don't get an error, I just get a blank page when I try to update something. The error has to have something to do with the upload, because even if I don't upload something new, the updating doesn't work (like when I only want to change text).
The upload stuff is a little messy but it's all for private use only. It posts an image and creates a resized copy as well.

I'm still a noob, so try to explain for dummies & show me exactly what to change ;)

[code=php:0]
<?
if ($_GET['action'] == "") {
$table = "mytable";
include('connect.php');

$result = mysql_query ("SELECT * FROM $table WHERE id='$id'") or print ("Can't select entry.<br />" . $sql . "<br />" . mysql_error());
while ($row = mysql_fetch_array($result)) {
$id = $row["id"];
$old_timestamp = $row["timestamp"];
$old_draft = $row["draft"];
$old_title = $row["title"];
$old_title = str_replace('"','\'',$old_title);
$old_media = $row["media"];
$old_movyear = $row["year"];
$old_rate = $row["rate"];
$old_reviewimg = $row["reviewimg"];
$old_photo1 = $row["photo1"];
$old_photo2 = $row["photo2"];
$old_photo3 = $row["photo3"];
$old_entry = $row["entry"];

$old_month = date("F",$old_timestamp);
$old_date = date("d",$old_timestamp);
$old_year = date("Y",$old_timestamp);
$old_time = date("H:i",$old_timestamp);
}


?>
<form method="post" action="update.php?action=submit" enctype="multipart/form-data">
<input type="hidden" name="id" value="<? echo $id ?>">
<b>Date:</b>
<select name="month">
<option value="<? echo $old_month ?>"><? echo $old_month ?></option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>

<input type="text" name="date" size="2" value="<? echo $old_date ?>">

<select name="year">
<option value="<? echo $old_year ?>"><? echo $old_year ?></option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2008</option>
<option value="2010">2010</option>
<option value="2010">2011</option>
<option value="2010">2012</option>
<option value="2010">2013</option>
<option value="2010">2014</option>
<option value="2010">2015</option>
<option value="2010">2016</option>
</select>

<input type="text" name="time" size="5" value="<? echo $old_time ?>">

<b>Draft:</b>
<select name="draft">
<option value="<? echo $old_draft ?>"><? echo $old_draft ?></option>
<option value="no">no</option>
<option value="yes">yes</option>
</select>

<br />
<br />
<b>Title:</b>
<br />
<input type="text" name="title" size="60" value="<? echo $old_title ?>" />

<br />
<br />
<b>Rating:</b>
<br />
<select name="rate">
<option value="<? echo $old_rate ?>"><? echo $old_rate ?></option>
<option value="rate00">0.0 | 00% - 09%</option>
<option value="rate05">0.5 | 10% - 19%</option>
<option value="rate10">1.0 | 20% - 29%</option>
<option value="rate15">1.5 | 30% - 35%</option>
<option value="rate20">2.0 | 36% - 43%</option>
<option value="rate25">2.5 | 44% - 51%</option>
<option value="rate30">3.0 | 52% - 60%</option>
<option value="rate35">3.5 | 61% - 69%</option>
<option value="rate40">4.0 | 70% - 78%</option>
<option value="rate45">4.5 | 79% - 84%</option>
<option value="rate50">5.0 | 85% - 91%</option>
<option value="rate55">5.5 | 92% - 96%</option>
<option value="rate60">6.0 | 97% - 100%</option>
</select>




<br />
<br />
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<b>Image:</b>
<br />
<?
if ($old_reviewimg == "") {
echo "<input type='file' name='reviewimg' size='60' />";
} else {
echo "<input type='text' name='reviewimg' size='60' value='$old_reviewimg' />";
}
?>
</td>
<td>
<? if ($old_reviewimg != "") {
echo "<img src='images/$old_reviewimg' height='50' />";
}
?>
</td>
</tr>
</table>

<table cellpadding="0" cellspacing="0">
<tr>
<td>
<b>Photo 1:</b>
<br />
<?
if ($old_photo1 == "") {
echo "<input type='file' name='photo1' size='60' />";
} else {
echo "<input type='text' name='photo1' size='60' value='$old_photo1' />";
}
?>
</td>
<td>
<? if ($old_photo1 != "") {
echo "<img src='images/small_$old_photo1' height='50' />";
}
?>
</td>
</tr>
</table>

<table cellpadding="0" cellspacing="0">
<tr>
<td>
<b>Photo 2:</b>
<br />
<?
if ($old_photo2 == "") {
echo "<input type='file' name='photo2' size='60' />";
} else {
echo "<input type='text' name='photo2' size='60' value='$old_photo2' />";
}
?>
</td>
<td>
<? if ($old_photo2 != "") {
echo "<img src='images/small_$old_photo2' height='50' />";
}
?>
</td>
</tr>
</table>

<table cellpadding="0" cellspacing="0">
<tr>
<td>
<b>Photo 3:</b>
<br />
<?
if ($old_photo3 == "") {
echo "<input type='file' name='photo3' size='60' />";
} else {
echo "<input type='text' name='photo3' size='60' value='$old_photo3' />";
}
?>
</td>
<td>
<?
if ($old_photo3 != "") {
echo "<img src='images/small_$old_photo3' height='50' />";
}
?>
</td>
</tr>
</table>


<br />
<textarea cols="80" rows="30" name="entry"><? echo $old_entry ?></textarea>
<br />
<input type="submit" name="submit" value="submit">
</form>


<?

} elseif (isset($_GET['action']) && $_GET['action'] == "submit") {

if ($reviewimg != "") {
$reviewimg = $_FILES['reviewimg']['name'];
$tmp_name = $_FILES['reviewimg']['tmp_name'];
if (!isset($reviewimg)) { exit; }
if(!is_uploaded_file($tmp_name)) {
echo "Fehler!";
switch ($_FILES['cover']['error']) {
case 1: echo "Zu groß"; break;
case 2: echo "Zu groß"; break;
case 3: echo "Nur tw übertragen"; break;
case 4: echo "Keine Datei angegeben"; break;
}
exit;
}
$uploadname ="/www/htdocs/images/$reviewimg";
move_uploaded_file($tmp_name, $uploadname);
}

//__ photo1 ___________________________________
if ($photo1 != "") {
$uploadedphoto1 = $_FILES['photo1']['tmp_name'];
$src1 = imagecreatefromjpeg($uploadedphoto1);
list($width1,$height1) = getimagesize($uploadedphoto1);
$newwidth1 = 460;
$newheight1 = 346;
$tmp1 = imagecreatetruecolor($newwidth1,$newheight1);
imagecopyresampled($tmp1,$src1,0,0,0,0,$newwidth1,$newheight1,$width1,$height1);
$filename1 = "/www/htdocs/images/". $_FILES['photo1']['name'];
imagejpeg($tmp1,$filename1,100);


#__ thumb _________________________________________________________
$uploadedthumb1 = $_FILES['photo1']['tmp_name'];
$srcthumb1 = imagecreatefromjpeg($uploadedthumb1);
list($widththumb1,$heightthumb1) = getimagesize($uploadedthumb1);
$newwidththumb1 = 140;
$newheightthumb1 = 105;

$src_top1 = ($src_height1 / 2) - ($dst_height1 / 2);
$src_left1 = ($src_width1 / 2) - ($dst_width1 / 2);

$tmpthumb1 = imagecreatetruecolor($newwidththumb1,$newheightthumb1);
imagecopyresampled($tmpthumb1,$srcthumb1,0,0,$src_top1,$src_left1,$newwidththumb1,$newheightthumb1,$widththumb1,$heightthumb1);
$thumbname1 = "/www/htdocs/images/small_". $_FILES['photo1']['name'];
imagejpeg($tmpthumb1,$thumbname1,100);
#___________________________________________________________________

imagedestroy($srcthumb1);
imagedestroy($tmpthumb1);
imagedestroy($src1);
imagedestroy($tmp1);
$photo1 =  $_FILES['photo1']['name'];
$thumb1 = "small_". $_FILES['photo1']['name'];
}
//__ photo2 ___________________________________
if ($photo2 != "") {
$uploadedphoto2 = $_FILES['photo2']['tmp_name'];
$src2 = imagecreatefromjpeg($uploadedphoto2);
list($width2,$height2) = getimagesize($uploadedphoto2);
$newwidth2 = 460;
$newheight2 = 346;
$tmp2 = imagecreatetruecolor($newwidth2,$newheight2);
imagecopyresampled($tmp2,$src2,0,0,0,0,$newwidth2,$newheight2,$width2,$height2);
$filename2 = "/www/htdocs/images/". $_FILES['photo2']['name'];
imagejpeg($tmp2,$filename2,100);

#__ thumb _________________________________________________________
$uploadedthumb2 = $_FILES['photo2']['tmp_name'];
$srcthumb2 = imagecreatefromjpeg($uploadedthumb2);
list($widththumb2,$heightthumb2) = getimagesize($uploadedthumb2);
$newwidththumb2 = 140;
$newheightthumb2 = 105;

$src_top2 = ($src_height2 / 2) - ($dst_height2 / 2);
$src_left2 = ($src_width2 / 2) - ($dst_width2 / 2);

$tmpthumb2 = imagecreatetruecolor($newwidththumb2,$newheightthumb2);
imagecopyresampled($tmpthumb2,$srcthumb2,0,0,$src_top2,$src_left2,$newwidththumb2,$newheightthumb2,$widththumb2,$heightthumb2);
$thumbname2 = "/www/htdocs/images/small_". $_FILES['photo2']['name'];
imagejpeg($tmpthumb2,$thumbname2,100);
#___________________________________________________________________

imagedestroy($srcthumb2);
imagedestroy($tmpthumb2);
imagedestroy($src2);
imagedestroy($tmp2);
$photo2 =  $_FILES['photo2']['name'];
$thumb2 = "small_". $_FILES['photo2']['name'];
}
//__ photo3 ___________________________________
if (($old_photo3 == "") && ($photo3 != "")) {
$uploadedphoto3 = $_FILES['photo3']['tmp_name'];
$src3 = imagecreatefromjpeg($uploadedphoto3);
list($width3,$height3) = getimagesize($uploadedphoto3);
$newwidth3 = 460;
$newheight3 = 346;
$tmp3 = imagecreatetruecolor($newwidth3,$newheight3);
imagecopyresampled($tmp3,$src3,0,0,0,0,$newwidth3,$newheight3,$width3,$height3);
$filename3 = "/www/htdocs/images/". $_FILES['photo3']['name'];
imagejpeg($tmp3,$filename3,100);

#__ thumb _________________________________________________________
$uploadedthumb3 = $_FILES['photo3']['tmp_name'];
$srcthumb3 = imagecreatefromjpeg($uploadedthumb3);
list($widththumb3,$heightthumb3) = getimagesize($uploadedthumb3);
$newwidththumb3 = 140;
$newheightthumb3 = 105;

$src_top3 = ($src_height3 / 2) - ($dst_height3 / 2);
$src_left3 = ($src_width3 / 2) - ($dst_width3 / 2);

$tmpthumb3 = imagecreatetruecolor($newwidththumb3,$newheightthumb3);
imagecopyresampled($tmpthumb3,$srcthumb3,0,0,$src_top3,$src_left3,$newwidththumb3,$newheightthumb3,$widththumb3,$heightthumb3);
$thumbname3 = "/www/htdocs/images/small_". $_FILES['photo3']['name'];
imagejpeg($tmpthumb3,$thumbname3,100);
#___________________________________________________________________

imagedestroy($srcthumb3);
imagedestroy($tmpthumb3);
imagedestroy($src3);
imagedestroy($tmp3);
$photo3 =  $_FILES['photo3']['name'];
$thumb3 = "small_". $_FILES['photo3']['name'];
}


$month = htmlspecialchars(strip_tags($_POST['month']));
$date = htmlspecialchars(strip_tags($_POST['date']));
$year = htmlspecialchars(strip_tags($_POST['year']));
$time = htmlspecialchars(strip_tags($_POST['time']));
$timestamp = strtotime($month . " " . $date . " " . $year . " " . $time);
$id = $_POST['id'];
$title = htmlspecialchars(addslashes($_POST['title']));
$draft = htmlspecialchars(addslashes($_POST['draft']));
$movyear = addslashes($_POST['movyear']);
$rate = addslashes($_POST['rate']);
$entry = addslashes($_POST['entry']);
include('connect.php');

$result = mysql_query("UPDATE $table SET timestamp='$timestamp', title='$title', draft='$draft', year='$movyear', rate='$rate', reviewimg='$reviewimg', photo1='$photo1', photo2='$photo2', photo3='$photo3', entry='$entry' WHERE id='$id'") or print ("Can't update entry.<br />" . $sql . "<br />" . mysql_error());

if ($result != false) {
print "<strong>$title</strong> has been updated!";
}
mysql_close();
}
?>
[/code]

Thanks in advance :)

Share this post


Link to post
Share on other sites
Your URL directory was this:

[code]$filename3 = "/www/htdocs/images/"[/code]


try changing it into this instead, every single url you have change your 'singel slashes' to 'double slashes'. . .

[code]$filename3 = "//www//htdocs//images//"[/code]

or the other way

[code]$filename3 = "\\www\\htdocs\\images\\"[/code]

hope this helps

Share this post


Link to post
Share on other sites
Mhmm thanks, but I don't really think thats the problem, because it works with the same code in my "post new entry" form. It just doesn't work in this editing form... (?_?)

Share this post


Link to post
Share on other sites
Anyone else have any ideas? I'm sure it's something in the form or before the uploading happens.
I'm so bad at spotting errors, especially because I'm still a noob :/

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.