images:
id (auto incrementing also the primary key)
name
size
created
image_path
gallery_type_id
gallery_type:
gallery_type_id
gallery_type_desc
i am trying to create an upload form with a drop down menu (using the select function) what i want to do is in the dropdown menu display the gallery_type_desc in order by gallery_type_id. i have got this code so far but it dont work. i dont suppose anyone could have a look through and explain what i need to add or change that would be really helpfull. im new to php so any help would be really gratefull!
upload form code: (i get a parse error on the coloured line)
<?php
// Check if a file has been uploaded
if(isset($_FILES['uploaded_file'])) {
// Make sure the file was sent without errors
if($_FILES['uploaded_file']['error'] == 0) {
$target_path = "images/";
$target_path = $target_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploaded_file']['name']).
" has been uploaded";
$dbLink = new mysqli('localhost', 'root', '', 'gallery');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
} // You missed this closing curly brace here
// Gather all required data
$name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
$mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
$size = intval($_FILES['uploaded_file']['size']);
$image_path = $dbLink->real_escape_string($target_path);
$gallery_type = $dbLink->real_escape_string($_POST['gallery_type']);
$query = "INSERT INTO `images` (`name`, `mime`, `size`, `data`, `created`, `image_path`, `gallery_type_id`)
VALUES ('{$name}', '{$mime}', {$size}, '', NOW(), '{$image_path}', '{$gallery_type}')";
$dbLink->query($query);
}
else {
echo 'Error! A file was not sent!';
}
}
}
// Echo a link back to the main page
echo '<p>Click <a href="member-index.php">here</a> to go back</p>';
?>
Less error-prone, saves having to use a counter, easier to read. If you are creating double quoted html attributes then try surrounding them in single quotes and the constant PHP_EOL does
but correctly picks the right one for the operating sytem it is hosted on.
If $gallery is only destined to be used for the next few lines, then shortening it to something like $gall or even $g that makes no big difference and is arguably easier to read too.
ahhh wow thank you for that. i completly forgot i needed to define my db again.
it now picks up some information in the drop down menu but not the info i want
it gives me a error saying:
NOTICE: undefined offset: 1 in c:/wamp/www/Blean_Photos/upload.php on line 39.
NOTICE: undefined offset: 2 in c:/wamp/www/Blean_Photos/upload.php on line 39.
NOTICE: undefined offset: 3 in c:/wamp/www/Blean_Photos/upload.php on line 39.
etc
which corrosponds to this:
echo $galleryTypes[$i][‘gallery_type_desc’];
any ideas what to change?
ive tried changing my for loop to this:
for($i = 1; $i < $num_results+1; $i++)
and starting my gallery_type_id at 0 but nothing has worked
it uploads to the folder okay but it doesnt write to the database due to that. i thought changing the [‘gallery_type’] to either [‘gallery_type_id’] or [‘gallery_type_desc’] but that didnt make any difference.