2017-01-03 123 views
0

我想插入產品的詳細信息到數據庫中,但它不會加入到數據庫中也出現此錯誤這是我的代碼將數據插入到數據庫...但它不插入到了數據庫

「通知:會話已經開始 - 在C忽略的session_start() :\ XAMPP \ htdocs中\君威\ ADMIN \ insert_products.php第2行」

<?php 
session_start(); 
echo "WELCOME: "."<b>". $_SESSION['user']."</br>"; 
    if(!isset($_SESSION['ISLOGIN'])){ 
     echo "<script>window.open('login.php?log=NOT AN ADMIN!!','_self')</script>"; 
     die; 
    } 
    else{ 
?> 


<!doctype> 
<?php 
include("./include/db.php"); 
?> 

<html> 
    <head> 
    <title>INSERT PRODUCTS</title> 
    <script src="//cdn.tinymce.com/4/tinymce.min.js"></script> 
    <script>tinymce.init({ selector:'textarea' });</script> 
    </head> 
    <body bgcolor="black"> 
    <form method="post" action="insert_products.php" enctype="multipart/form-data"> 
     <table width="830" height="600px" bgcolor="gray" align="center" border="5" style="color:white" > 
      <tr > 
       <th colspan="7" align="center"><h1>Insert New Posts Here!</h1></th> 
      </tr> 
      <tr> 
       <td align="right" ><b>NAME:</b></td> 
       <td><input type="text" name="name" required/></td> 
      </tr> 
      <tr > 
       <td align="right" ><b>IMAGE:</b></td> 
       <td><input type="file" name="img" required/></td> 
      </tr> 
      <tr> 
       <td align="right" ><b>PRICE:</b></td> 
       <td><input type="text" name="price" required/></td> 
      </tr> 
      <tr> 
       <td align="right" /><b>CATEGORY:</b></td> 
       <td><select name="getcat" required/> 
         <option>Select</option> 


          <?php 


         if (!$db) { 
         echo "Error: Unable to connect to MySQL."; 
         exit; 
          } 

         $q="select * from cat" ; 
         $run_cat=mysql_query($q); 
         while($rows=mysql_fetch_array($run)){ 
          $catid=$rows['id']; 
          $cattit=$rows['title']; 
          echo "<option>$cattit</option>"; 
         } 

         ?> 
        </select> 
       </td> 
      </tr> 

      <tr > 
       <td align="right" ><b>DESCIRPTION:</b></td> 
       <td><textarea type="text" name="desc" cols="20" rows="10"></textarea></td> 
      </tr> 
      <tr> 
       <td align="center" colspan="7"><input type="submit" name="sub" value="Insert Product"></td> 
      </tr> 


     </table> 
    </form> 
    </body> 
</html> 

<?php 
    if(isset($_POST['sub'])){ 
     $name=$_POST['name']; 
     $price=$_POST['price']; 
     $getcat=$_POST['getcat']; 
     $desc=$_POST['desc']; 
     $img=$_FILES['img']['name']; 
     $imgt=$_FILES['img']['tmp_name']; 
     move_uploaded_file($imgt,"pro-images/$img"); 

     $insert="insert into products (img,price,name,category,desc)values ('$img','$price','$name','$getcat','$desc')"; 

     $insert_pro=mysql_query($insert); 
     if($insert_pro){ 
      echo "<script>alert('PRODUCT HAS BEEN UPLOADED')</script>"; 
      echo"<script>window.open('index.php?insertprod','_self')</script>"; 
     } 
    } 

    } 
?> 
+0

會話已經啓動。註釋行session_start() – digit

+0

你有開始會話db.php? –

+0

您是否已經在db.php頁面中使用session_start()? –

回答

0

檢查會話在th運行在腳本的頂部代替session_start();

If(session_status() === PHP_SESSION_DISABLED || PHP_SESSION_NONE) { 
    session_start(); 
} 

如果它仍然存在。說明由db.php發出的錯誤