0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.