So everything up to the insert statement works perfectly. I know the database is connecting because I can select information from the database with the first two statements. I also know that the execute_statment3 works because no errors are being printed off and when it is put into the sql the statement is inserted the way it should be. Therefore the problem lies somewhere with the communication between the script and phpmyadmin. Please help I have been staring at this problem for two days and am going rather crazy.

<?php

session_start();

$hostname = 'localhost';
$username = '####';
$password = '####';


$connection = mysql_connect($hostname, $username, $password) 
or die ('Connection error!!!');


$database = '####';
mysql_select_db($database);  


$uid = $_SESSION['ID'];  
$album = $_POST['albumname'];  
$description = $_POST['description'];  
$filename = $_FILES["upload_file"]["name"];  
$filetype = $_FILES["upload_file"]["type"];
$filesize = $_FILES["upload_file"]["size"];
$file_on_server = $_FILES["upload_file"]["tmp_name"];  


if ($filetype == "image/jpeg") {  
    $file_copy_name = date(m.d.y_H.i.s) . ".jpg";  
        copy($file_on_server, "uploads/" . $file_copy_name);  


    print "<br>";  
    print "<img src = \"uploads/$file_copy_name\">";    


    print "<br>";  
    $ret = system("pwd");  


    $picture = "uploads/$file_copy_name";  
}


$execute_statement = "SELECT * FROM ImageAlbums WHERE Album = '$album'";


$results = mysql_query($execute_statement) or die ('Error executing SQL statement!!!');


while($item = mysql_fetch_array($results))


{ 
  $album2 = $item['Album'];
}

if ($album2 == $album)


{
    $execute_statement2 = "SELECT * FROM ImageAlbums WHERE Album = '$album'";


    $results2 = mysql_query($execute_statement2) or die ('Error executing SQL statement2!!!');


        while ($row2 = mysql_fetch_array($results2)) {


        $AID = $row2["AlbumID"];
        }


    $execute_statement3 = "INSERT INTO Images (`ImageID`, `AlbumID`, `Description`, `Extensions`) VALUES ('NULL', '$AID', '$description', '$file_copy_name')";      


    ($execute_statement3) or die ('Error executing SQL statement3!!!');

}


print "<br>";
print "<br>";
print $execute_statement3;
print "<br>";
print "<br>";
print $AID;
print "<br>";
print "<br>";
print $picture;


?>

I am using two databases for this script one of the databases is called ImageAlbums and has two columns called AlbumID and Album (AlbumID being a primary key). The second table is called Images and has four columns ImageID (primary key), AlbumID (foreign key), Description and Extensions.

share|improve this question
feedback

2 Answers

up vote 1 down vote accepted

You are not running the statement

($execute_statement3) or die ('Error executing SQL statement3!!!');

Try:

mysql_query($execute_statement3);

Also, make sure you escape all the variables.

share|improve this answer
Thank you, Thank you, Thank you. It works! – Rob Horlacher Apr 12 '11 at 3:52
feedback

make sure that the user you are connecting with in the php script has privileges for insert statements. you could be using a db user with only select privs...

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.