--_47a76e33-97da-4466-be8e-e0fb2478ca51_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi all=2C
I am new to php=2C I am just learning it at the moment. I hope you can help=
me with my code.
Thanks in advance!
I want the page to allow users to edit or delete an existing uploaded file.=
But after testing the script in the browser the delete option is working 1=
0 out 0f 10=3B
but the edit is not. I don't know what I am doing wrong.
Here's my code:
<?php # edit_file.php
// This page allows users to edit or delete existing URL records.
$page_title =3D 'Edit a file'=3B
// Check for a URL ID.
if (isset($_GET['uid'])) { // Page is first accessed.
$uid =3D (int) $_GET['uid']=3B
} elseif (isset($_POST['uid'])) { // Form has been submitted.
$uid =3D (int) $_POST['uid']=3B
} else { // Big problem.
$uid =3D 0=3B
}
//<!-- BEGIN if ($uid <=3D 0)-->
if ($uid <=3D 0) { // Do not proceed!
echo '<p><font color=3D"red">This page has been accessed incorrectly=
!</font></p>'=3B
include ('./includes/footer.html')=3B
exit()=3B // Terminate execution of the script.
}//<!-- END if ($uid <=3D 0)-->
require_once ('./mysql_connect.php')=3B // Connect to the database.
$counter=3D1=3B
$name=3D $_FILES[$filename]['name']=3B
$size=3D$_FILES[$filename]['size']=3B
$type=3D$_FILES[$filename]['type']=3B
$temp_name=3D$_FILES[$filename]['temp_name']=3B
$error=3D$_FILES[$filename]['error']=3B
//<!-- BEGIN if (isset($_POST['submitted']))-->
if (isset($_POST['submitted'])) { // Handle the form.
//<!-- BEGIN if ($_POST['which'] =3D=3D 'delete')-->
if ($_POST['which'] =3D=3D 'delete') { // Delete the record.
// This part is working fine.
} else { // Edit the uploaded file .
for ($i =3D 0=3B $i < $counter=3B $i++) { // Handle the uploaded file=
..
$filename =3D 'upload' . $i=3B
$description =3D 'description' . $i=3B
// Check for a file.
if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] !=
=3D 2)) {
// Check for a description
if (!empty($_POST[$description])) {
$d =3D "'" . escape_data($_POST [$description]) . "'"=
=3B
} else {
$d =3D 'NULL
}
// Update the record to the database.
$query =3D "UPDATE uploads SET file_name=3D'$name'=2C
file_size=3D'$size'=2C file_type=3D'$type'=2C descripti=
on=3D'$d' WHERE
upload_id=3D$uid"=3B
$result =3D mysql_query ($query)=3B
if ($result) {
// Return the upload_id from the database.
$upload_id =3D mysql_insert_id()=3B
// Move the file over.
if (move_uploaded_file($_FILES[$filename]['tmp_name'=
]=2C "uploads/$upload_id")) {
echo '<p>New file ' . ($i + 1) . ' has bee=
n uploaded!</p>'=3B
} else { // File could not be moved.
echo '<p><font color=3D"red">File ' . ($i +=
1) . 'could not be moved.</font></p>'=3B
}//end move_uploaded_file
} else { // If the query did not run OK
echo '<p><font color=3D"red">Yoursubmission could not be=
processed due to a system error. We apologize
for any inconvenience.</font></p>'=3B
}//end if(result)
} // End of if (isset($the_file)...
} // End of FOR loop.
} // End of Edit/Delete if-else.
} // End of the main submitted conditional.
// --------- DISPLAY THE FORM ---------
//Retrieve the uploads's current information.
$query =3D "SELECT file_name=2C ROUND(file_size/1024) AS fs=2C file_type=
=2C
description=2C DATE_FORMAT(date_entered=2C '%e %M %Y') AS d FRO=
M uploads
WHERE upload_id=3D$uid"=3B
$result =3D mysql_query ($query)=3B
//get all of the information first record
list($file_name=2C $fs=2C $file_type=2C $d=2C $de)=3D mysql_fetch_array ($=
result=2C MYSQL_NUM)=3B
?>
<form action=3D"edit_file.php" method=3D"post">
<input type=3D"hidden" name=3D"MAX_FILE_SIZE" value=3D"524288" />
<fieldset><legend>Edit a File:</legend>
<p><b>Select One:</b> <input type=3D"radio" name=3D"which" value=
=3D"edit"
checked=3D"checked" /> Edit <input type=3D"radio"=
name=3D"which" value=3D"delete" />
Delete</p>
<?php
//Retrieve the uploads's current information.
$query =3D "SELECT file_name=2C ROUND(file_size/1024) AS fs=2C=
file_type=2C
description=2C DATE_FORMAT(date_entered=2C '%e %M %Y'=
) AS de FROM uploads
WHERE upload_id=3D$uid"=3B
$result =3D mysql_query ($query)=3B
//print the current file's information in the browser
while ($row =3D mysql_fetch_array($result=2C MYSQL_ASSOC)) {
echo '<table border=3D"0" width=3D"100%" cellspacing=3D"3"=
cellpadding=3D"3" align=3D"center">
<tr>
<td align=3D"left" width=3D"20%"><font size=3D"+1">Fi=
le Name</font></td>
<td align=3D"center" width=3D"20%"><font size=3D"+1">=
File Size</font></td>
<td align=3D"left" width=3D"20%"><font size=3D"+1">Up=
load Date</font></td>
</tr>'=3B
// Display each record.
echo " <tr>
<td align=3D\"left\">{$row['file_name']}</a></td>
<td align=3D\"center\">{$row ['fs']}kb</td>
<td align=3D\"left\">{$row ['de']}</td>
</tr>\n"=3B
}
?>
<?php // Create the inputs.
for ($i =3D 0=3B $i < $counter=3B $i++) {
echo '<p><b>File:</b> <input type=3D"file" name=3D"upload=
' . $i . '" /></p>
<p><b>Description:</b> <textarea name=3D"descriptio=
n' . $i . '" cols=3D"40"
rows=3D"5">'.$d.'</textarea></p>
'=3B
}
?>
</fieldset>
<input type=3D"hidden" name=3D"submitted" value=3D"TRUE" />
<?php // Store the required hidden values.
echo ' <input type=3D"hidden" name=3D"uid" value=3D"'=
. $uid . '" /> '=3B
?>
<div align=3D"center"><input type=3D"submit" name=3D"submit" v=
alue=3D"Submit" /></div>
</form>
<?php mysql_close()=3B // Close the database connection.
?>
Thanks in advance!
Estelle
=
--_47a76e33-97da-4466-be8e-e0fb2478ca51_--
