PHP停止工作一半没有错误

时间:2012-01-03 17:52:10

标签: php mysql file-upload

下面是我的代码,用于上传图像,然后创建一些包含其MySQL数据库的JSON。

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

?>

出于某种原因没有来自

的代码
$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;`

向前工作。因此,我无法更新我的数据库,甚至无法检查数据库中已有的内容。可能导致此问题的任何想法? :)。只是为了澄清Echos的工作。

1 个答案:

答案 0 :(得分:2)

很简单,mysql_result如果给定行不存在传递的字段,则返回false。第0行中不存在“SmallImages”或“LargeImages”,因为没有实际的SQL错误,die()会输出空白消息。您应该确保您要查找的密钥确实存在于查询结果中。


既然问题已经满足,我必须建议您选择其他数据库API。阅读new PHP docs about choosing the right MySQL API。您使用的旧扩展程序已过时,不支持预准备语句或OOP,通常被认为不适合新项目。