2016-05-28 7 views
1

私はデータベースから製品の詳細を取得しています。ここで私のサンプルコードは、私は製品のイメージを表示することができませんです!誰でも私を助けてくれますか?「リソースを読み込めませんでした:サーバーが404のステータスで応答しました(見つかりません)」

データベース内の製品の詳細を挿入するコード:

<!DOCTYPE> 
<?php 
include("includes/db.php"); 
?> 
<html> 
<head> 
<title> Inserting product</title> 

<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script> 
    <script> 
    tinymce.init({ selector:'textarea' }); 
    </script> 

</head> 
<body bgcolor="skyblue"> 
<form action="insert_product.php" method="post" enctype="multipart/form-data"> 
    <table align="center" width="700" border="2" bgcolor="orange"> 
    <tr align="center"> 
      <td colspan="7"><h2>Insert New Post Here.</h2></td> 
    </tr> 
    <tr> 
      <td align="right"><b>Product Title:</b></td> 
      <td><input type="text" name="product_title" size="50" required /></td> 
    </tr> 
    <tr> 
      <td align="right"><b>Product Category:</b></td> 
      <td> 
      <select name="product_cat" required> 
      <option>Select a categogory</option> 
      <?php 
      $get_cats = "select * from categories"; 
    $run_cats = mysqli_query($con, $get_cats); 

    while($row_cats=mysqli_fetch_array($run_cats)){ 

     $cat_id = $row_cats['cat_id']; 
     $cat_title = $row_cats['cat_title']; 
     echo "<option value='$cat_id'>$cat_title</option>"; 
    } 
      ?> 
      </select> 
      </td> 
    </tr> 
    <tr> 
      <td align="right"><b>Product Brand:</b></td> 
      <td> 
      <select name="product_brand" required> 
      <option>Select a Brand</option> 
      <?php 
      $get_brands = "select * from brands"; 
    $run_brands = mysqli_query($con, $get_brands); 

    while($row_brands=mysqli_fetch_array($run_brands)){ 

     $brand_id = $row_brands['brand_id']; 
     $brand_title = $row_brands['brand_title']; 
     echo "<option value='$brand_id'>$brand_title</option>"; 
    } 
      ?> 
      </select> 
      </td> 
    </tr> 
    <tr> 
      <td align="right"><b>Product Image:</b></td> 
      <td><input type="file" name="product_image" required/></td> 
    </tr> 
    <tr> 
      <td align="right"><b>Product Price:</b></td> 
      <td><input type="text" name="product_price" size="50" required/></td> 
    </tr> 
    <tr> 
      <td align="right"><b>Product Description:</b></td> 
      <td><textarea name="product_desc" cols="20" rows="10"></textarea></td> 
    </tr> 
    <tr> 
      <td align="right"><b>Product Keywords</b></td> 
      <td><input type="text" name="product_keywords" size="50" required/></td> 
    </tr> 
    <tr align="center"> 
      <td colspan="7"><b><input type="submit" name="insert_post" value="Insert Product Now"/></b></td> 
    </tr> 
    </table> 
</form> 
</body> 
</html> 
<?php 
    if(isset($_POST['insert_post'])){ 
     //getting the text data from the fields. 
    $product_title = $_POST ['product_title']; 
    $product_cat = $_POST ['product_cat']; 
    $product_brand = $_POST ['product_brand']; 
    $product_price = $_POST ['product_price']; 
    $product_desc = $_POST ['product_desc']; 
    $product_keywords = $_POST ['product_keywords']; 
     //getting the image data from the fields. 
     $product_image = $_FILES['product_image'][name]; 
     $product_image_tmp = $_FILES['product_image']['tmp_name']; 

     move_uploaded_file($product_image_tmp,"product_images/$product_image"); 

     $insert_product = "insert into products (product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords) values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc',' $product_image','$product_keywords')"; 
    $insert_pro = mysqli_query($con,$insert_product); 
    if($insert_pro) { 
     echo "<script>alert('Product has been inserted!')</script>"; 
     echo "<script>window.open('insert_product.php','_self')</script>"; 
    } 
    } 
?> 

機能部。

<?php 
$con = mysqli_connect("localhost","root","","ecommerce"); 
//getting the categories 
function getcats(){ 
    global $con; 
    $get_cats = "select * from categories"; 
    $run_cats = mysqli_query($con, $get_cats); 

    while($row_cats=mysqli_fetch_array($run_cats)){ 

     $cat_id = $row_cats['cat_id']; 
     $cat_title = $row_cats['cat_title']; 
     echo "<li><a href='#'>$cat_title</a></li>"; 
    } 

    } 

//getting the Brands 
function getBrands(){ 
    global $con; 
    $get_brands = "select * from brands"; 
    $run_brands = mysqli_query($con, $get_brands); 

    while($row_brands=mysqli_fetch_array($run_brands)){ 

     $brand_id = $row_brands['brand_id']; 
     $brand_title = $row_brands['brand_title']; 
     echo "<li><a href='#'>$brand_title</a></li>"; 
    } 

    } 

    function getpro() { 
     global $con; 

     $get_pro = "select * from products order by RAND() LIMIT 1,6"; 
     $run_pro = mysqli_query($con, $get_pro); 
     while($row_pro=mysqli_fetch_array($run_pro)){ 
      $pro_id = $row_pro['product_id']; 
      $pro_cat = $row_pro['product_cat']; 
      $pro_brand = $row_pro['product_brand']; 
      $pro_title = $row_pro['product_title']; 
      $pro_price = $row_pro['product_price']; 
      $pro_image = $row_pro['product_image']; 
      echo " 
      <div id='single_product'> 
      <h3>$pro_title</h3> 
      <img src='\\ecommerce\admin_area\product_images\$pro_image' width='180' height='180' /> 
      <p><b> $pro_price </b></p> 
      </div> 
      "; 
     } 
     }        
?> 




**The web page to display all details** 
    <!DOCTYPE> 
<?php 
include("functions/functions.php"); 
?> 
<html> 
    <head> 
     <title>Gal Baking Services LTD online Shop.</title> 
    <link rel="stylesheet" href="admin_area/product_images/style.css" media="all" /> 
    </head> 
<body> 
    <div class="main_Wrapper"> 

     <div class="header_wrapper"> 
     <img id="logo" src="images/ad bunner.jpg" /> 
     <img id="bunner" src="images/ad bunner.jpg" /> 
     </div> 
     <div class="menubar"> 
      <ul id="menu"> 
       <li><a href="#">Home</a></li> 
       <li><a href="#">All products</a></li> 
       <li><a href="#">My account</a></li> 
       <li><a href="#">Sign up</a></li> 
       <li><a href="#">Shopping cart</a></li> 
       <li><a href="#">Contact Us</a></li> 
      </ul> 
      <div id="form"> 
       <form method="get" action="result.php" enctype="multipart/form-data"> 
        <input type="text" name="user_query" placeholder="Search a product" /> 
        <input type="submit" name="search" value="search" /> 
       </form> 
      </div> 
     </div> 
     <div class="content_wrapper"> 
     <div id="sidebar"> 

      <div id="sidebar_title">Categories</div> 
      <ul id="carts"> 
      <?php getcats();?> 
      </ul> 
     <div id="sidebar_title">Brands</div> 

      <ul id="carts"> 
      <?php getBrands();?> 
      </ul> 

     </div> 
     </div> 
     <div id="content_area"> 
      <div id="products_box"> 

      <?php getpro(); ?> 

      </div> 
     </div> 
     </div> 
     <div id="footer"> 
      <h2 style="text-align:center; padding-top:30px;">&copy;2016 by www.krumblefresh.com </h2> 
     </div> 
    </div> 
</body> 
</html> 

答えて

0

私はご参加とご支援のためのみんなに感謝したいです。 mysqlデータベースから画像を表示する方法について私のコードで乱れた後、私のコードは、insert_product.phpファイルの次の行にいくつかばかげた間違いをしただけであることを認識した。 "$ product_image = $ _FILES ['product_image'] [name]; "。 'name'を一重引用符で囲みませんでした。 '$ product_image = $ _FILES [' product_image '] [' name '] ;. また、次の行に*

$ insert_product =「製品 (product_cat、product_brand、PRODUCT_TITLE、PRODUCT_PRICE、product_desc、product_image、product_keywords) 値 ( '$のproduct_cat'、 '$のproduct_brandに挿入'、' $ product_title '、' $ product_price '、' $ product_desc '、 ' $ product_image '、' $ product_keywords ') ";

*、私がすることになって$ product_image .Its、

$ insert_product =近くの単一引用符の内側の空白が含まれていた「、製品に (product_cat、product_brand、PRODUCT_TITLE、PRODUCT_PRICE、product_descを挿入product_image、product_keywords) 値 ( '$ product_cat'、 '$ product_brand'、 '$ product_title'、 '$ product_price'、 '$ product_desc'、 '$ product_image'、 '$ product_keywords') "; ありがとうございます。

関連する問題