10-15-2010, 05:09 AM
|
#3 (permalink)
|
|
The Wanderer
Join Date: Aug 2010
Location: West Coast, New Zealand
Posts: 5
Thanks: 2
|
Quote:
Originally Posted by Village Idiot
Without seeing your code there is nothing we can to do help you besides refer you to Google.
|
Hi, sorry about the long day, I had to drive to our nearest city (340km away) and back, that kept me off the computer :(
I have included the offending part of my script. It is an index.php file, the first once downloaded when the administrator logs in. It is a controller file: the 'add artist' and 'delete artist' are working, so I have not shown them. I have included the entire part of the script concerned with editing artists, although it is the 'Process editform' that I am having trouble with.
PHP Code:
//Show form to edit existing artist
if (isset($_POST['action']) and $_POST['action'] == 'Edit') {
include($_SERVER['DOCUMENT_ROOT'] . '/../code2/admindb.inc.php');
$id = mysqli_real_escape_string($link, $_POST['id']);
$sql = "SELECT * FROM artists WHERE id = '$id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = 'Error fetching artist details.';
include($_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php');
exit();
}
$row = mysqli_fetch_array($result);
$pagetitle = 'Edit Artist';
$action = 'editform';
$fname = $row['fname'];
$lname = $row['lname'];
if (is_null($row['filename'])) {
$filename = '';
} else {
$filename = $row['filename'];
}
$bio = $row['bio'];
$id = $row['id'];
$button = 'Update Artist';
include 'form.html.php';
exit();
}
//Process editform
if (isset($_GET['editform'])) {
if ($_FILES["image"]["size"] > 0) {
if ((($_FILES["image"]["type"] == "image/gif")
|| ($_FILES["image"]["type"] == "image/jpeg")
|| ($_FILES["image"]["type"] == "image/pjpeg"))
&& ($_FILES["image"]["size"] < 200000))
{
if ($_FILES["image"]["error"] > 0)
{
echo "Return Code: " . $_FILES["image"]["error"] . "<br />";
} else {
if (file_exists("../../meetArtists/" . $_FILES["image"]["name"]))
{
$filename = $_FILES["image"]["name"];
exit();
} else {
move_uploaded_file($_FILES["image"]["tmp_name"],
"../../meetArtists/" . $_FILES["image"]["name"]);
$filename = $_FILES["image"]["name"];
}
}
} else {
echo "Invalid file";
}
}
include $_SERVER['DOCUMENT_ROOT'] . '/../code2/admindb.inc.php';
$fname = mysqli_real_escape_string($link, $_POST['fname']);
$lname = mysqli_real_escape_string($link, $_POST['lname']);
$bio = mysqli_real_escape_string($link, $_POST['elm1']);
$id = (int) $id = mysqli_real_escape_string($link, $_POST['id']);
if ($fname == '' || $lname == '') {
$error = 'You must give the artist a first name and a surname. Click ‘back’ and try again.';
include($_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php');
exit();
}
if (file_exists("../../meetArtists/" . $_FILES["image"]["name"])) {
$filename = $_FILES["image"]["name"];
$sql = "UPDATE artists SET
fname = '$fname',
lname = '$lname',
filename = '$filename',
bio = '$bio'
WHERE id = '$id'";
} else {
$sql = "UPDATE artists SET
fname = '$fname',
lname = '$lname',
bio = '$bio'
WHERE id = '$id'";
}
if (!mysqli_query($link, $sql)) { //+2
$error = 'Error updating selected artist.';
include($_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php');
exit();
}
header('Location: .');
exit();
}
I hope this is enough. Many thanks in advance for any help I might receive.
Cliff
|
|
|
|