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

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>";
        }
    }

  }
?>
douwei8096
douwei8096 在我评论会议之后...我没有得到任何错误,但事情是我的数据没有;t加入数据库..am卡在那里
3 年多之前 回复
dongtao1262
dongtao1262 删除会话后你得到了什么确切的错误?
3 年多之前 回复
dtpa98038
dtpa98038 不,我没有在db.php页面上使用session_start()
3 年多之前 回复
duanaoshu1989
duanaoshu1989 我尝试删除会话兄弟,但仍然没有数据添加到数据库中
3 年多之前 回复
dongwang3066
dongwang3066 您是否已在db.php页面中使用session_start()?
3 年多之前 回复
dtfo55908
dtfo55908 你有没有在db.php上开始会话?
3 年多之前 回复
dsla94915
dsla94915 会话已经开始。评论一行session_start()
3 年多之前 回复

1个回答



检查会话是否正在运行,使用脚本顶部代替session_start(); </ p>

< pre> If(session_status()=== PHP_SESSION_DISABLED || PHP_SESSION_NONE){
session_start();
}
</ code> </ pre>

如果它仍然存在。 说明db.php </ p>
</ div>发出的错误

展开原文

原文

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐