0

Below is my code which is used to upload images and then create some JSON containing their URLs to a MySQL Database.

<?php
ini_set('error_reporting', E_ALL);

//Get Libraries
require_once($_SERVER['DOCUMENT_ROOT'].'/Scripts/mobile_device_detect.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/Scripts/WideImage/WideImage.php');

$Name = $_GET['name'];
$NumberImages = $_GET['numberImages'];

$FirstSetNumber = 1;
$SecondSetNumber = 2; 

$uploading = $_POST['Uploading'];

if($uploading  == "true")
{
    $FirstSetNumber = $_POST['FirstSetNumber'];
    $SecondSetNumber = $_POST['SecondSetNumber'];

    $Name = $_POST['Name'];
    $NumberImages = $_POST['NumberImages'];

    echo "This is the set (".$FirstSetNumber."-".$SecondSetNumber.") for the Lighthouse (".$Name.") Which will consist of ".$NumberImages." pictures";

    function connectToDatabase()
    {
        mysql_connect("host", "user", "password"); 
        mysql_select_db("light_information") or die(mysql_error());
    }
    connectToDatabase();

    $query = mysql_query('SELECT * FROM Lighthouses WHERE Name="'.$Name.'"') or die(mysql_error());

    $PageType = mysql_result($query, 0, "PageType");

    if($PageType = "englandtrinityhouse" || $PageType = "englandprivate" || $PageType = "scotlandnlb" || $PageType = "scotlandprivate")
    {
        $TypeFolder = "lighthouses";
    }   

    $folderLocation = "../resources/images/".$TypeFolder."/".str_replace(" ", "-", $Name)."/";
    if(!file_exists($folderLocation))
    {
        mkdir($folderLocation, 0777);
    }   

    function findFileExtension($filename) 
    { 
         $filename = strtolower($filename) ; 
         $exts = split("[/\\.]", $filename) ; 
         $n = count($exts)-1; 
         $exts = $exts[$n]; 
         return $exts; 
    }    


     //Thumbnail 1
     $thumbnail1Extension = findFileExtension($_FILES['Thumbnail1']['name']);
     $thumbnail1Name = str_replace(" ", "-", $name)."-Thumbnail-".$FirstSetNumber.".".$thumbnail1Extension;
     $thumbnail1Location = $folderLocation.$thumbnail1Name;
     $URLThumbnail1 = str_replace("../", "http://www.worldwidelighthouses.com/", $thumbnail1Location);

     if(!move_uploaded_file($_FILES['Thumbnail1']['tmp_name'], $thumbnail1Location))
     { 
        echo("Canny Move Thumbnail ".$FirstSetNumber);
     } 

     //Thumbnail 2
     $thumbnail2Extension = findFileExtension($_FILES['Thumbnail2']['name']);
     $thumbnail2Name = str_replace(" ", "-", $name)."-Thumbnail-".$SecondSetNumber.".".$thumbnail2Extension;
     $thumbnail2Location = $folderLocation.$thumbnail2Name;
     $URLThumbnail2 = str_replace("../", "http://www.worldwidelighthouses.com/", $thumbnail2Location);

     if(!move_uploaded_file($_FILES['Thumbnail2']['tmp_name'], $thumbnail2Location))
     { 
        echo("Canny Move Thumbnail ".$SecondSetNumber);
     } 

     //Large Image 1
     $LargeImage1Extension = findFileExtension($_FILES['LargeImage1']['name']);
     $LargeImage1Name = str_replace(" ", "-", $name)."-LargeImage-".$FirstSetNumber.".".$LargeImage1Extension;
     $LargeImage1Location = $folderLocation.$LargeImage1Name;
     $URLLargeImage1 = str_replace("../", "http://www.worldwidelighthouses.com/", $LargeImage1Location);

     if(!move_uploaded_file($_FILES['LargeImage1']['tmp_name'], $LargeImage1Location))
     { 
        echo("Canny Move Large ".$FirstSetNumber);
     } 

     //Large Image 2
     $LargeImage2Extension = findFileExtension($_FILES['LargeImage2']['name']);
     $LargeImage2Name = str_replace(" ", "-", $name)."-LargeImage-".$SecondSetNumber.".".$LargeImage2Extension;
     $LargeImage2Location = $folderLocation.$LargeImage2Name;
     $URLLargeImage2 = str_replace("../", "http://www.worldwidelighthouses.com/", $LargeImage2Location);

     if(!move_uploaded_file($_FILES['LargeImage2']['tmp_name'], $LargeImage2Location))
     { 
        echo("Canny Move Large ".$SecondSetNumber);
     }

     $FirstSetNumber = $FirstSetNumber + 2;
     $SecondSetNumber = $SecondSetNumber + 2;

     $ThumbnailImagesJSONfromDB = mysql_result($query, 0, "SmallImages") or die(mysql_error());
     $LargeImagesJSONfromDB = mysql_result($query, 0, "LargeImages") or die(mysql_error());

     echo "Dis Far";
     echo $ThumbnailImagesJSONfromDB;

     // HTML to display data

?>

For some reason no code from

$ThumbnailImagesJSONfromDB = mysql_result($query, 0, "SmallImages") or die(mysql_error());
     $LargeImagesJSONfromDB = mysql_result($query, 0, "LargeImages") or die(mysql_error());

     echo "Dis Far";
     echo $ThumbnailImagesJSONfromDB;`

Onwards Works. Therefore I cannot update my database or even check what is already on the database. Any ideas what could be causing this issue? :). Just to clarify neither of the Echos work.

4
  • PHP may be timing out on you. At the beginning of your script, try adding set_time_limit(0); Commented Jan 3, 2012 at 17:55
  • 1
    Off topic - perhaps you want to hide your mysql login details from your script? Commented Jan 3, 2012 at 17:55
  • 1
    Just to confirm, is display_errors set? Commented Jan 3, 2012 at 17:56
  • Welcome to SO @DanTonyBrown. A few tips about asking questions: Don't post so much code. Try to isolate what's giving you problems and only post the relevant info. Definitely don't give out sensitive info like usernames and passwords. You should consider your DB compromised as anybody with acccess to this question can see your sensitive info. Commented Jan 3, 2012 at 18:12

1 Answer 1

2

Quite simply, mysql_result returns false if the field passed does not exist for the given row. 'SmallImages' or 'LargeImages' does not exist in row 0 and since there were no actual SQL errors your die() outputs a blank message. You should make sure the keys you are looking for actually exist in your query results.


Now that the question has been satisfied I must advise you to choose a different database API. Read over the new PHP docs about choosing the right MySQL API. The older extension you are using is outdated, does not support prepared statements or OOP and is generally considered not suitable for new projects.

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

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.