The Problem:
I make an array with a list of items in the database. When you choose to add/edit a picture on a particular row a separate page called ‘files.html.php’ opens with upload options. When you click ‘upload’ nothing happens, but the page refreshes. If you hover your mouse over the ‘upload’ button, the url bar displays the code for the current page for some reason.
Here’s the index.php code:
// Adding and Editing Pictures
if ((isset($_POST[‘action’]) and $_POST[‘action’] == ‘addpic’) or (isset($_GET[‘action’]) and $_GET[‘action’] == ‘addpic’))
{
include ‘…/…/…/includes/link_athensgacalendar.php’;
if (isset($_POST[‘id’]))
{
$id = mysqli_real_escape_string($link, $_POST[‘id’]);
}
else if (isset($_GET[‘id’]))
{
$id = mysqli_real_escape_string($link, $_GET[‘id’]);
}
$sql = “SELECT id, picture, mimetype, filedata FROM memberdiscounts WHERE id=‘$id’”;
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = ‘Error fetching details.’;
include ‘…/…/…/includes/error.html.php’;
exit();
}
$row = mysqli_fetch_array($result);
$pagetitle = 'Edit Picture';
$action = 'editpicform';
$picture = $row['picture'];
$mimetype = $row['mimetype'];
$filedata = $row['filedata'];
$id = $row['id'];
$button = 'Submit Picture';
include 'files.html.php';
exit();
}
// if (isset($_POST[‘action’]) and $_POST[‘action’] == ‘upload’)
if (isset($_POST[‘action’]) and $_POST[‘action’] == ‘upload’)
{
// Bail out if the file isn’t really an upload
if (!is_uploaded_file($_FILES[‘upload’][‘tmp_name’]))
{
$error = ‘There was no file uploaded!’;
include ‘…/…/…/includes/error.html.php’;
exit();
}
$uploadfile = $_FILES[‘upload’][‘tmp_name’];
$uploadname = $_FILES[‘upload’][‘name’];
$uploadtype = $_FILES[‘upload’][‘type’];
$uploaddata = file_get_contents($uploadfile);
include '../../../includes/link_athensgacalendar.php';
// Prepare user-submitted values for safe database insert
$uploadname = mysqli_real_escape_string($link, $uploadname);
$uploadtype = mysqli_real_escape_string($link, $uploadtype);
$uploaddata = mysqli_real_escape_string($link, $uploaddata);
$sql = "UPDATE memberdiscounts SET
picture = '$uploadname',
mimetype = '$uploadtype',
filedata = '$uploaddata'
WHERE id='$id'";
if (!mysqli_query($link, $sql))
{
$error = 'Database error storing file!';
include '../../../includes/error.html.php';
exit();
}
header('Location: .');
exit();
}
if (isset($_GET[‘action’]) and
($_GET[‘action’] == ‘view’ or $_GET[‘action’] == ‘download’) and
isset($_GET[‘id’]))
{
include ‘…/…/…/includes/link_athensgacalendar.php’;
$id = mysqli_real_escape_string($link, $_GET['id']);
$sql = "SELECT picture, mimetype, filedata
FROM memberdiscounts
WHERE id = '$id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = 'Database error fetching requested file.';
include '../../../includes/error.html.php';
exit();
}
$file = mysqli_fetch_array($result);
if (!$file)
{
$error = 'File with specified ID not found in the database!';
include '../../../includes/error.html.php';
exit();
}
$picture = $file['picture'];
$mimetype = $file['mimetype'];
$filedata = $file['filedata'];
$disposition = 'inline';
if ($_GET['action'] == 'download')
{
$mimetype = 'application/octet-stream';
$disposition = 'attachment';
}
// Content-type must come before Content-disposition
header("Content-type: $mimetype");
header("Content-disposition: $disposition; filename=$filename");
header('Content-length: ' . strlen($filedata));
echo $filedata;
exit();
}
if (isset($_POST[‘action’]) and $_POST[‘action’] == ‘deletepic’ and
isset($_POST[‘id’]))
{
include ‘…/…/…/includes/link_athensgacalendar.php’;
$id = mysqli_real_escape_string($link, $_GET['id']);
$sql = "UPDATE memberdiscounts SET
picture = '',
mimetype = '',
filedata = ''
WHERE id = '$id'";
if (!mysqli_query($link, $sql))
{
$error = 'Database error deleting requested file.';
include '../../../includes/error.html.php';
exit();
}
header('Location: .');
exit();
}
if (isset($_POST[‘action’]) and $_POST[‘action’] == ‘editpic’)
{
include ‘…/…/…/includes/link_athensgacalendar.php’;
$pagetitle = 'Post';
$action = ‘addpic’;
$picture = ‘’;
$mimetype = ‘’;
$filedata = ‘’;
$id = ‘’;
$button = ‘Add Picture’;
include ‘files.html.php’;
exit();
}
any ideas?