Please ignore – I have worked out the problem
Hi there
I have a php script that successfully will allow me to upload an image the images folder on my server.
[code]
<?
//print_r($_POST);
unset($imagename);
if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;
if(!isset($_FILES[‘image_file’]))
$error[“image_file”] = “An image was not found.”;
$imagename = basename($_FILES[‘image_file’][‘name’]);
echo $imagename;
if(empty($imagename))
$error[“imagename”] = “The name of the image was not found.”;
if(empty($error))
{
$newimage = “../images/” . $imagename;
echo ‘<img src=”‘.$newimage.'” />’;
$result = @move_uploaded_file($_FILES[‘image_file’][‘tmp_name’], $newimage);
if(empty($result))
$error[“result”] = “There was an error moving the uploaded file.”;
}
?>
<form method=”POST” enctype=”multipart/form-data” name=”image_upload_form” action=”<?$_SERVER[“PHP_SELF”];?>”>
<p><input type=”file” name=”image_file” size=”20″></p>
<p><input type=”submit” value=”Upload Image” name=”action”></p>
</form>
<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo “<br>n”;
}
}
?>
And I also have a php page that successfully updates a database with a new record.
I have tried to combine the two so when adding a new record, it allows you to select an image and upload it and store the filename in the database with the other details of the new record.
My code is adding the new record but is not adding any data for the imagename to the database or uploading the image.
Here is my php code:
[code]
<?php
if (isset($source)) {
if ($source == ‘add_musician2.htm’) {
include “config.php”;
$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die (“Cannot connect to database”);
// ——————–
// Deal with image file
// ——————–
unset($imagename);
if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;
if(!isset($_FILES[‘image_file’]))
$error[“image_file”] = “An image was not found.”;
$imagename = basename($_FILES[‘image_file’][‘name’]);
echo $imagename;
if(empty($imagename))
$error[“imagename”] = “The name of the image was not found.”;
if(empty($error))
{
$newimage = “../images/” . $imagename;
echo ‘<img src=”‘.$newimage.'” />’;
$result = @move_uploaded_file($_FILES[‘image_file’][‘tmp_name’], $newimage);
if(empty($result))
$error[“result”] = “There was an error moving the uploaded file.”;
}
$name = $_POST[‘bandname’];
if(isset ($_POST[‘brass’])) {
$brass = 1;
} else {
$brass = 0;
}
if(isset ($_POST[‘earlymusic’])) {
$earlymusic = 1;
} else {
$earlymusic = 0;
}
if(isset ($_POST[‘jazz’])) {
$jazz = 1;
} else {
$jazz = 0;
}
if(isset ($_POST[‘keyboards’])) {
$keyboards = 1;
} else {
$keyboards = 0;
}
if(isset ($_POST[‘percussion’])) {
$percussion = 1;
} else {
$percussion = 0;
}
if(isset ($_POST[‘rockandpop’])) {
$rockandpop = 1;
} else {
$rockandpop = 0;
}
if(isset ($_POST[‘strings’])) {
$strings = 1;
} else {
$strings = 0;
}
if(isset ($_POST[‘traditional’])) {
$traditional = 1;
} else {
$traditional = 0;
}
if(isset ($_POST[‘vocal’])) {
$vocal = 1;
} else {
$vocal = 0;
}
if(isset ($_POST[‘woodwind’])) {
$woodwind = 1;
} else {
$woodwind = 0;
}
if(isset ($_POST[‘world’])) {
$world = 1;
} else {
$world = 0;
}
$website = $_POST[‘link’];
$description = $_POST[“description”];
$query = “INSERT INTO musicianstb(name, brass, earlymusic, jazz, keyboards, percussion, rockandpop, strings,
traditional, vocal, woodwind, world, website, description, imagename)
VALUES(‘$name’,’$brass’,’$earlymusic’,’$jazz’,’$keyboards’,’$percussion’,’$rockandpop’,’$strings’,’$traditional’,’$vocal’,’$woodwind’,
‘$world’,’$website’,’$description’,’$imagename’)”;
$result = mysql_query($query);
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}
echo “New Musician added”;
echo “</br>”;
echo “</br>”;
echo “<br>Return to admin page <a href=http://www.superact.org.uk/admin
target=_self><b>http://www.superact.org.uk/admin</b></a>”;
echo “</br>”;
mysql_close($db);
} else {
echo ‘<p><b>You have accessed this page inappropriately!</b></p>’;
}
} else {
echo ‘<p><b>You have accessed this page inappropriately!</b></p>’;
}
?>
Any help much appreciated
Paul