So this is my first php application I have ever made and I'm goign full out on it. I have a little bit of c++ and java skill so I'm not that stupid when it comes to programming. The problem that I am having is my insert query is not working at all and I have no clue why. So if somebody could check out why this problem is occurring that whould be awesome.
// Fetch the photo array sent by preupload.php
$photos_uploaded = $_FILES['photo_filename'];
// Fetch the photo caption array
$photo_caption = $_POST['photo_caption'];
// Fetch the photo category id
$photo_category_id = $_POST['category_name'];
try {
include("config.inc.php");
while( $counter <= count($photos_uploaded) ) {
if($photos_uploaded['size'][$counter] > 0) {
if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types)) {
$result_final .= "File ".($counter+1)." is not a photo<br />";
}
else {
// Prepare the query for execution
$results = $db->prepare("INSERT INTO gallery_photos(photo_filename, photo_caption, photo_category) VALUES( ?, ?, ?)");
// Set the parameters
$results->bindParam(1, $hpoto_filename);
$results->bindParam(2, $photo_caption[$counter]);
$results->bindParam(3, $photo_category_id);
$photo_filename = '0';
// Execute the insert
$results->execute();
$results = null;
$results = $db->query("SELECT category_name FROM gallery_category WHERE category_id='".$photo_category_id."'");
$photo_category = $results->fetch();
//$photo_category = $results->fetch(PDO::FETCH_ASSOC);
// Retrieve the ID from the last insert
$new_id = $db->lastInsertId();
$filetype = $photos_uploaded['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = $new_id.".".$extention;
//mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );
//$db->beginTransaction();
$select = $db->prepare("UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'");
$select->execute();
//$db->commit();
// Store the orignal file
copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$photo_category['category_name']."/".$filename);