dongsaoshuo4326 2015-08-25 08:33
浏览 35
已采纳

php错误发生时不确认后面是什么错误

I wrote a php script and it was working fine but now I am getting an error in it but i am not sure what actually causing an error in my script because i defined a custom message in my function like this:

$error_display = "<div class='errormsgbox'>An error occured. Please Try Again</div>";

Is there any way to get what error I am getting with little detail so that U can fix it is it possible

here is my script

<?php
// check for empty errors 
$sucess = null;
$error_display = null;
$slug_title = null;

if (isset($_POST['formsubmitted'])) {
$error = array();

//Check Video Title
    if (empty($_POST['video_title'])) {
        $error[] = 'You must enter a video title';
    } else {
        $vid_title = $_POST['video_title'];
        //Create Slug using name
        function create_slug($string){
            $string = preg_replace( '/[^A-Za-z0-9\. ]/', '', $string );
                $string = strtolower($string);
                $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
            return $slug;
            }
            $slug_title = create_slug($vid_title);
    }


//Check Ref ID Start
// The length we want the unique reference number to be  
    $unique_ref_length = 6;  

    // A true/false variable that lets us know if we've  
    // found a unique reference number or not  
    $unique_ref_found = false;  

    // Define possible characters.  
    // Notice how characters that may be confused such  
    // as the letter 'O' and the number zero don't exist  
    $possible_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ234567890";  

    // Until we find a unique reference, keep generating new ones  
    while (!$unique_ref_found) {  

        // Start with a blank reference number  
        $unique_ref = "";  

        // Set up a counter to keep track of how many characters have   
        // currently been added  
        $i = 0;  

        // Add random characters from $possible_chars to $unique_ref   
        // until $unique_ref_length is reached  
        while ($i < $unique_ref_length) {  

            // Pick a random character from the $possible_chars list  
            $char = substr($possible_chars, mt_rand(0, strlen($possible_chars)-1), 1);  

            $unique_ref .= $char;  

            $i++;  

        }  

        // Our new unique reference number is generated.  
        // Lets check if it exists or not  
        $query = "SELECT `vid_code` FROM `tblmevids` WHERE `vid_code`='".$unique_ref."'";  
        $result = mysqli_query($conn, $query);  
        if (mysqli_num_rows($result)==0) {  

            // We've found a unique number. Lets set the $unique_ref_found  
            // variable to true and exit the while loop  
            $unique_ref_found = true;  

        }  

    }  
//Check Ref ID End



//Check Channel Selection
    if ($_POST['video_channel'] == 0) {
        $error[] = 'You must select Channel';
    } else {
        $channel_selectid = $_POST['video_channel'];
    }

    $activation_vid = $_POST['active_status'];
    $featured_vid = $_POST['featured_status'];
    $metadescription = $_POST['video_meta_descp'];
    $submit_by = $_SESSION['USERNAME'];
    $metakeywords = $_POST['video_meta_kywrd'];
    $get_new_date = date('Y-m-d G:i:s');
    $set_new_vide_code = date("d").$unique_ref;
    $slug_final = $set_new_vide_code."-".$slug_title;

//Check Dailymotion Code
    if (empty($_POST['video_dm_code'])) {
        $error[] = 'Dailymotion video is is must';
    } else {
        $dm_vid_code = $_POST['video_dm_code'];
            //Grab Dailymotion Video Duration
            $duration_total='https://api.dailymotion.com/video/'.$dm_vid_code.'?fields=duration_formatted,thumbnail_360_url';
            $json_duration = file_get_contents($duration_total);
                    $get_duration = json_decode($json_duration, TRUE);
            $dm_duration_final = $get_duration['duration_formatted'];
            $dm_make_thumbnail = $get_duration['thumbnail_360_url'];
            $main_image = imagecreatefromstring(file_get_contents($dm_make_thumbnail));
            // Load the logo image
            $logoImage = imagecreatefromstring(file_get_contents($site_water_mark_path));
            imagealphablending($logoImage, true);
            // Get dimensions
            $imageWidth=imagesx($main_image);
            $imageHeight=imagesy($main_image);
            $logoWidth=imagesx($logoImage);
            $logoHeight=imagesy($logoImage); 
            // Paste the logo
            imagecopy(
               // source
            $main_image,
               // destination
            $logoImage,
               // destination x and y
            $imageWidth-$logoWidth, $imageHeight-$logoHeight,
               // source x and y
            0, 0,
               // width and height of the area of the source to copy
            $logoWidth, $logoHeight);
                ////////////////////////
            imagejpeg($main_image, '../video_thumbs/'.$set_new_vide_code.'.jpg'); 
    }


//Check Youtube Code
    if (empty($_POST['video_yt_code'])) {
        $yt_vid_code = null;
    } else {
        $yt_vid_code = $dm_duration_final;
    }

// INSERT values into database Function Start
if (empty($error)) {
    $sql = "INSERT INTO `tblmevids` (vid_code, vid_title, vid_slug, vid_cat_id, vid_addedby_id, dm_vid_code, yt_vid_code, vid_act_stat, vid_featured_stat, vid_dm_duration, vid_yt_duration, vid_seo_descp, vid_seo_kywrd, vid_add_date)VALUES ('$set_new_vide_code', '$vid_title', '$slug_final', '$channel_selectid', '$submit_by', '$dm_vid_code', '$yt_vid_code', '$activation_vid', '$featured_vid', '$dm_duration_final', '$yt_duration_final', '$metadescription', '$metakeywords', '$get_new_date')";
        $result=mysqli_query($conn,$sql);
        if($result){
                // INSERT Social Data Start
                $fb_status = intval(0);
                $twt_status = intval(0);
                $sql_share = "INSERT INTO `tblsocial_share` (vidsc_code, vid_fb_sstat, vid_twt_sstat)VALUES ('$set_new_vide_code', '$fb_status', '$twt_status')";
                $result_social=mysqli_query($conn,$sql_share);
                    if($result_social) {
                $sucess = "<div class='success'>Perfect!!! New video has been added</div>";
                    } else {
                $error_display = "<div class='errormsgbox'>1 An error occured. Please Try Again</div>";
                    }
                // INSERT Social Data END
        } else {
                $error_display = "<div class='errormsgbox'>2 An error occured. Please Try Again</div>";
        }

} else { //Erros Display '
        $error_show =  '';
        foreach ($error as $key => $values) {
            $error_show .=' <li>'. $values.'</li>'; 
            $error_display = "<div class='errormsgbox'> <ol>".$error_show."</ol></div>";      
        }
}
// INSERT values into database Function End
}
?>
  • 写回答

1条回答 默认 最新

  • dpgu5074 2015-08-25 08:50
    关注

    Where is your $conn (connection variable) set? You have no result form query, so maybe this is the problem.

    If insert query generate error, just check it:

    mysqli_query($conn,$sql) or die(mysqli_error($conn));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP