无错误 无数据存储到数据库中



运行时,没有收到任何错误,但甚至没有数据存储到数据库中。所有数据库连接均有效。请帮助解开这个谜团。数据库结构也有 17 个字段,我用正确的数据类型进行了检查。

表单页面编码

<?php include('config.php');
if(isset($_POST['submit']))
{
$purchase_date=$_POST['purchase_date'];
$assession_no=$_POST['assession_no'];
$book_title=$_POST['book_title'];
$edition=$_POST['edition'];
$publisher=$_POST['publisher'];
$year_of_publish=$_POST['year_of_publish'];
$volume=$_POST['volume'];
$number_of_pages=$_POST['number_of_pages'];
$source=$_POST['source'];
$cost=$_POST['cost'];
$quantity=$_POST['quantity'];
$note=$_POST['note'];
$category=$_POST['category'];   
$sql=mysql_query("insert into add_book(b_id,purchase_date,assession_no,book_title,edition,publisher,year_of_publish,volume,number_of_pages,source,cost,quantity,note,category) values('','$purchase_date','$assession_no','$book_title','$edition','$publisher','$year_of_publish','$volume','$number_of_pages','$source','$cost','$quantity','$note','$category')");
} ?>
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action=""  class="basic-grey" >
     <label>
        <span>Purchase Date:</span>
        <input name="purchase_date" type="text" class="datepicker" id="popup_container" required/>
    </label>
     <label>
        <span>Assession No. :</span>
        <input name="assession_no" type="text" value="" required/>
    </label>
    <label>
        <span>Book Title :</span>
        <input  type="text" name="book_title" id="title" placeholder="" value="" required/>
    </label>
     <label>
        <span>Edition :</span>
        <input name="edition" type="text" value="" required/>
    </label>
     <label>
        <span>Publisher :</span>
        <input name="publisher" type="text" value="" required/>
    </label>
   <label>
        <span>Year of Publish:</span>
        <input type="text"  name="year_of_publish" value="" required/>
    </label>
         <label>
        <span>Volume:</span>
        <input name="volume" type="text" value="" required/>
    </label>
    <label>
        <span>Page:</span>
        <input name="number_of_pages" type="text" value="" required/>
    </label>
    <label>
        <span>Source:</span>
        <input name="source" type="text" value="" required/>
    </label>
    <label>
        <span>Cost:</span>
        <input name="cost" type="text" value="" required/>
    </label>
      <label>
        <span>Quantity :</span>
        <input name="quantity" type="text" value="" required/>
    </label>
    <label>
        <span>General Note :</span>
        <textarea id="message" name="note" placeholder="" value=""></textarea>
    </label> 
     <label>
        <span>Category :</span><select name="category" required>
        <option value="Engineering">Engineering</option>
        <option value="General">General</option>
        <option value="Competitive">Competitive</option>
        <option value="Reading Space">Reading Space</option>
        </select>
    </label> 

                                                    <label>Image Upload</label>
                                                    <input type="file"  name="photo" /></span>
                                                                <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>                                                       


     <label>
        <span>&nbsp;</span> 
        <input type="submit" name="submit" class="button" /> 
    </label>    
</form>
</body>
</html>

配置.php编码

<?php
$con=mysql_connect("localhost","root","") ;
$db=mysql_select_db("friendslib",$con) ; 
?>

把它放在页面顶部error_reporting(E_ALL);ini_set("display_errors", 1);

并将表单类型设置为发布和$sql=mysql_query(" YOur code") 或 die(mysql_error());

这是错误:

<form action=""  class="basic-grey" >

将其更改为:

<form action=""  class="basic-grey" method="post">

默认的表单方法是get,如果不设置,则假定它是get的。

您正在检查$_POST['submit']因此永远不会设置。

注意:

不要使用 MySQL 函数,它们已被弃用,并将在下一版本的 PHP 中删除。

您没有处理任何错误! 你怎么知道你没有收到任何错误?

把它放在页面的顶部:

error_reporting(-1);
ini_set('display_errors', 'On');

额外说明:

不要使用 MySQL

函数,你需要使用 MySQL 或 PDO。

使用此代码:

$sql=mysql_query("insert into add_book(purchase_date,assession_no,book_title,edition,publisher,year_of_publish,volume,number_of_pages,source,cost,quantity,note,category) values('$purchase_date','$assession_no','$book_title','$edition','$publisher','$year_of_publish','$volume','$number_of_pages','$source','$cost','$quantity','$note','$category')");
}

注意:

我看到您的查询but you are leaving it empty in the values中有b_id! 所以我解决了这个问题。 我希望它有所帮助。

第二次编辑:

这是您发布的错误,它显示mysqli错误,但您正在使用mysql! 您不能将mysqlimysql一起使用。

您能否确保在配置和other_php_page.php中使用 MySQLi 或 MySQL.php?

你不处理任何事情必须像这样填充动作和方法:

<form action="NAME OF THIS PAGE like page.php" method="post" >
</form>

'

使用以下

代码解决错误:

<?php 
$con=mysqli_connect("localhost","root","", "friendslib") ;
error_reporting(-1);
ini_set('display_errors', 'On');
if(isset($_POST['submit']))
{
$purchase_date=$_POST['purchase_date'];
$assession_no=$_POST['assession_no'];
$book_title=$_POST['book_title'];
$edition=$_POST['edition'];
$publisher=$_POST['publisher'];
$year_of_publish=$_POST['year_of_publish'];
$volume=$_POST['volume'];
$number_of_pages=$_POST['number_of_pages'];
$source=$_POST['source'];
$cost=$_POST['cost'];
$quantity=$_POST['quantity'];
$note=$_POST['note'];
$category=$_POST['category'];   
$sql=mysqli_query($con,"insert into add_book(purchase_date,assession_no,book_title,edition,publisher,year_of_publish,volume,number_of_pages,source,cost,quantity,note,category) values('$purchase_date','$assession_no','$book_title','$edition','$publisher','$year_of_publish','$volume','$number_of_pages','$source','$cost','$quantity','$note','$category')");
} ?>
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action=""  class="basic-grey" method="post" >
     <label>
        <span>Purchase Date:</span>
        <input name="purchase_date" type="text" class="datepicker" id="popup_container" required/>
    </label>
     <label>
        <span>Assession No. :</span>
        <input name="assession_no" type="text" value="" required/>
    </label>
    <label>
        <span>Book Title :</span>
        <input  type="text" name="book_title" id="title" placeholder="" value="" required/>
    </label>
     <label>
        <span>Edition :</span>
        <input name="edition" type="text" value="" required/>
    </label>
     <label>
        <span>Publisher :</span>
        <input name="publisher" type="text" value="" required/>
    </label>
   <label>
        <span>Year of Publish:</span>
        <input type="text"  name="year_of_publish" value="" required/>
    </label>
         <label>
        <span>Volume:</span>
        <input name="volume" type="text" value="" required/>
    </label>
    <label>
        <span>Page:</span>
        <input name="number_of_pages" type="text" value="" required/>
    </label>
    <label>
        <span>Source:</span>
        <input name="source" type="text" value="" required/>
    </label>
    <label>
        <span>Cost:</span>
        <input name="cost" type="text" value="" required/>
    </label>
      <label>
        <span>Quantity :</span>
        <input name="quantity" type="text" value="" required/>
    </label>
    <label>
        <span>General Note :</span>
        <textarea id="message" name="note" placeholder="" value=""></textarea>
    </label> 
     <label>
        <span>Category :</span><select name="category" required>
        <option value="Engineering">Engineering</option>
        <option value="General">General</option>
        <option value="Competitive">Competitive</option>
        <option value="Reading Space">Reading Space</option>
        </select>
    </label> 

                                                    <label>Image Upload</label>
                                                    <input type="file"  name="photo" /></span>
                                                                <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>                                                       


     <label>
        <span>&nbsp;</span> 
        <input type="submit" name="submit" class="button" /> 
    </label>    
</form>
</body>
</html>

最新更新