dongpo2340 2017-01-03 06:15
浏览 114

这是我将数据插入数据库的代码...但它不会插入到数据库中

I want to insert product details into database, but it doesn't get added into database also I get this error

"Notice: A session had already been started - ignoring session_start() in C:\xampp\htdocsegal\admin\insert_products.php on line 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>";
        }
    }

  }
?>
  • 写回答

1条回答

  • douri4459 2017-01-03 06:38
    关注

    Check if session is running using at the top of your script in place of session_start();

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

    If it persists. State the error issued by db.php

    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能