开发者

php error (not work online)

开发者 https://www.devze.com 2023-02-15 21:44 出处:网络
I write a shopping cart site and i can run this site in my wamp localhost well. I host this site in eu5.org. When i run the site,my category.php is not load well (nothing is load). The code of my cate

I write a shopping cart site and i can run this site in my wamp localhost well. I host this site in eu5.org. When i run the site,my category.php is not load well (nothing is load). The code of my category.php file is bellow. I don't find the error. Please help me.

<?php
session_start();
$action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : '';
$catid = (isset($_GET['catid']) && $_GET['catid'] != '') ? $_GET['catid'] : ''; 

include('../include/functions.php');
check_user();
include('theme/header.php');
include('theme/admin_menu.php');

?>
<div id="content">
<?php
switch($action){
    case 'add':开发者_如何学Python 
    view_add_category();
    break;
    case 'edit':
    view_edit_category($catid);
    break;
    case 'delete':
    delete_category($catid);
    break;  
    default:
    show_category();
    }
?>  
<div id="add_menu">
    <?php
        echo "<a href='product.php?action=add'><input type='submit' value='Add New Product'/></a>";     
        echo "<a href='category.php?action=add'><input type='submit' value='Add New Category' /></a>";
    ?>
</div>
<div id="products">

Choose the category to see the products.
</div>
</div>

<?php
    function show_category()
    {
        include('..\configdb.php');
        $sql="SELECT * FROM categorys WHERE parent_id = 0";
        $result=mysqli_query($mysqli,$sql) or die(mysqli_error());

        echo "<div id='cat_list'>";
        echo "<table border='0' width='250'>";
        echo "<tr height='35' bgcolor='green' style='color:#EEEEEE'><div><font color='black'>
                <td width='180' align='center'>Categories</td></tr>";


        while($row=mysqli_fetch_array($result)){
                $cat_id=$row['cat_id'];
                $cat_name=$row['cat_name'];

                $bg=($bg=='#eeeeee' ? '#ffffff':'#eeeeee');
                echo "<tr bgcolor=".$bg." ><td width='100'><b>".$cat_name."</b></td><td width='30'><a href='category.php?action=edit&catid=$cat_id'>Edit</a></td><td width='30'><a href=\"javascript:confirm_delete('Are you sure you want to delete?','category.php?action=delete&catid=".$cat_id."');\">Delete</a></td></tr>";

            $sql2="SELECT * FROM categorys WHERE parent_id=$cat_id AND cat_id<>0";
            $result2=mysqli_query($mysqli,$sql2) or die(mysqli_error());
            while($row=mysqli_fetch_array($result2)){
                $cat_id=$row['cat_id'];
                $cat_name=$row['cat_name'];

                $bg=($bg=='#eeeeee' ? '#ffffff':'#eeeeee');
                echo "<tr bgcolor=".$bg." ><td width='100'><a href='javascript:showproducts($cat_id)'>&nbsp;&nbsp;&nbsp;".$cat_name."</a></td><td width='30'><a href='category.php?action=edit&catid=$cat_id'>Edit</a></td><td width='30'><a href=\"javascript:confirm_delete('Are you sure you want to delete?','category.php?action=delete&catid=".$cat_id."');\">Delete</a></td></tr>";
            }
        } #while($row=mysqli_fetch_array($result)){
        echo "</table>";
        echo "</div>";
    }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function delete_category($catid)
{
        include('../configdb.php');
        $sql_del="DELETE  FROM categorys WHERE cat_id= '$catid' ";
        $result_del=mysqli_query($mysqli, $sql_del) or die(mysqli_error());
        if($result_del) echo "<meta http-equiv=\"refresh\" content=\"0;URL=category.php\">";
}   
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function view_edit_category($catid)
    {
        include('../configdb.php');
        $sql="SELECT * FROM categorys WHERE cat_id='$catid'";
        $result=mysqli_query($mysqli,$sql) or die(mysqli_error());
        $row=mysqli_fetch_array($result);
        $parentid=$row['parent_id'];
        $catname=$row['cat_name'];
        if(file_exists("../cat_images/".$row['cat_pic']) && !is_dir("../cat_images/".$row['cat_pic'])) {
            $cat_pic = "../cat_images/".$row['cat_pic'];
        } else {
            $cat_pic = "../cat_images/no.jpg";
        }

?>      
    <script src="../js/jquery.js"></script>
    <script>
    $(document).ready(function() {
    $("#change-pic").click(function () {
        $('input[type=file]').toggle();
        if($(this).html() == "Change Picture") {

        $(this).html("Cancel");
        $('img').hide();
        $('input[type=file]').focus();
        $('#changed-pic').val('1');

        } else {

        $(this).html("Change Picture");
        $('input[type=file]').val('');
        $('img').show();
        $('#changed-pic').val('0');
        }
    });
    });
        </script>
    <form class="cat_edit_form" id="cat_edit_form" method="post" action="<?php edit_category(); ?>"  enctype="multipart/form-data">
    <fieldset>
        <div>
            <label>Parent:</label>
             <?php
                include('../configdb.php');         
                $sql="SELECT cat_id,cat_name FROM categorys WHERE parent_id=0";
                $result=mysqli_query($mysqli,$sql) or die(mysqli_error());
                echo "<select name='parent_name' id='parent_name' length='15'>";

                echo "<option  value='0'>Root</option>";
                while($row=mysqli_fetch_array($result)){

                    $cat_id=$row['cat_id'];
                    $cat_name=$row['cat_name'];
                    if($cat_id==$parentid)
                    {
                        echo "<option selected='selected' value=".$cat_id.">".$cat_name."</option>";
                    }
                    else
                    {
                        echo "<option value=".$cat_id." >".$cat_name."</option>";
                    }
                }
                echo "</select>";
            ?>
        </div>
        <div>
            <label>Category Name:</label>
            <input type="text" class="field" id="cat_name" name="cat_name"  value="<?php echo $catname; ?>"/>
        </div>
        <div>
            <label>Picture:</label>
            <img src="<?php echo $cat_pic; ?>" width='120' height='144' />
            <input type="file" name="cat_pic" style="display: none" />
            <br />
            <span style="display: none">Choose Picture (or) </span>
            <a href="#" id="change-pic">Change Picture</a>
            <br /><br />
        </div>
        <div>
        <input type="hidden" name="cat_id" value="<?php echo $catid; ?>">
        </div>
        <div>
        <input id='changed-pic' type='hidden' name='changed_pic' value='0' />
        </div>        
        <div>
            <input type="submit" value="Edit" name="editcat" />
        </div>
    </fieldset>
</form>

<?php
    }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function edit_category()
{
    if(isset($_POST['editcat']))
    {
        $cat_id=$_POST['cat_id'];
        $parent_name=addslashes($_POST['parent_name']);
        $cat_name=addslashes($_POST['cat_name']);
        $changed_pic = $_POST['changed_pic'];

        if($changed_pic) {  
            $cat_pic = $_FILES['cat_pic']['name'];

            move_uploaded_file($_FILES['cat_pic']['tmp_name'], "../cat_images/" . $_FILES['cat_pic']['name']);
            include('../configdb.php');     
            $sql="UPDATE categorys SET cat_name='$cat_name', parent_id='$parent_name', cat_pic='$cat_pic' WHERE cat_id='$cat_id'";
            $result=mysqli_query($mysqli,$sql) or die(mysqli_error());              
        }else{
            include('../configdb.php');     
            $sql="UPDATE categorys SET cat_name='$cat_name', parent_id='$parent_name' WHERE cat_id='$cat_id'";
            $result=mysqli_query($mysqli,$sql) or die(mysqli_error());
        }
        if($result){

            header("location: category.php");   
        }
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function view_add_category()
{


?>
<form class="cat_form" id="cat_form" method="post" enctype="multipart/form-data" action="<?php add_category(); ?>" >
    <fieldset>
        <div>
            <label>Parent:</label>
             <?php
                include('../configdb.php');         
                $sql="SELECT cat_id,cat_name FROM categorys WHERE parent_id=0";
                $result=mysqli_query($mysqli,$sql) or die(mysqli_error());
                echo "<select name='parent_name' id='parent_name' length='15'>";
                echo "<option  value='0'>Root</option>";
                while($row=mysqli_fetch_array($result)){

                    $cat_id=$row['cat_id'];
                    $cat_name=$row['cat_name'];
                    echo "<option value=".$cat_id." >".$cat_name."</option>";
                }
                echo "</select>";
            ?>
        </div>
        <div>
            <label>Category Name:</label>
            <input type="text" class="field" id="cat_name" name="cat_name" />
        </div>
        <div>
            <label>Picture:</label>
            <input type="file" class="field" id="cat_image" name="cat_image" />
        </div>
        <div>
            <input type="submit" value="Add" name="addcat" />
        </div>
    </fieldset>
</form>

<?php       
}   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function add_category()
{
    if(isset($_POST['addcat']))
    {
        $parent_name=addslashes($_POST['parent_name']);
        $cat_name=addslashes($_POST['cat_name']);
        $cat_image = $_FILES['cat_image']['name'];

        move_uploaded_file($_FILES['cat_image']['tmp_name'], "../cat_images/" . $_FILES['cat_image']['name']);

        include('../configdb.php');
        $sql_insert="INSERT INTO categorys(cat_name, parent_id, cat_pic) VALUES ('$cat_name', '$parent_name', '$cat_image')";
        $result_insert=mysqli_query($mysqli,$sql_insert) or die(mysqli_error());
        if($result_insert){

            header("location: category.php");
        }
    }
}
?>


Add error_reporting(E_ALL); ini_set('display_errors', 'On'); on top of the page. This will show the error. Based on the error, we can provide information..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号