Php 无错误无数据存储到数据库中
当运行这段代码时并没有得到任何错误,甚至并没有数据存储到数据库中。所有数据库连接都有效。请帮我解开这个谜。数据库结构也有17个字段,我用正确的数据类型进行了检查 表单页面编码Php 无错误无数据存储到数据库中,php,mysql,database,Php,Mysql,Database,当运行这段代码时并没有得到任何错误,甚至并没有数据存储到数据库中。所有数据库连接都有效。请帮我解开这个谜。数据库结构也有17个字段,我用正确的数据类型进行了检查 表单页面编码 <?php include('config.php'); if(isset($_POST['submit'])) { $purchase_date=$_POST['purchase_date']; $assession_no=$_POST['assession_no']; $book_title=$_POST['bo
<?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> </span>
<input type="submit" name="submit" class="button" />
</label>
</form>
</body>
</html>
<?php
$con=mysql_connect("localhost","root","") ;
$db=mysql_select_db("friendslib",$con) ;
?>
您没有处理任何错误!你怎么知道你没有收到任何错误
将以下内容放在页面顶部:
error_reporting(-1);
ini_set('display_errors', 'On');
额外说明:
不要使用mysql函数。您需要使用mysqli或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')");
}
注:
我看到您在查询中有b_id
,但在值中却将其留空
!所以我把它修好了。我希望有帮助
第二次编辑:
这是您发布的错误,它显示了mysqli
错误,但您正在使用mysql
!您不能将mysqli
与mysql
一起使用
请确保您在config.php和您的另一个_php_page.php中都使用mysqli或mysql好吗?以下是错误:
<form action="" class="basic-grey" >
将其更改为:
<form action="" class="basic-grey" method="post">
是get
,如果不设置它,它将假定它是get
您正在检查$\u POST['submit']
,因此将永远不会设置它
注意:
不要使用mysql函数,它们已弃用,将在下一版本的PHP中删除。您需要使用mysqli或PDO。将其放在页面顶部
错误报告(E_全部);
ini设置(“显示错误”,1)
并将表单类型设置为post和
$sql=mysql\u query(“您的代码”)或die(mysql\u error()) 您不需要处理任何事情,必须填写以下操作和方法:
<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> </span>
<input type="submit" name="submit" class="button" />
</label>
</form>
</body>
</html>
回显您的查询并在db上手动运行它插入添加图书(图书id、购买日期、评估编号、图书标题、版本、出版商、出版年份、数量、页数、来源、成本、数量、注释、类别)值(“$purchase\u date”、“$assessment\u no”、“$book\u title”、“$edition”、“$publisher”、“$year\u of\u publish”、“$volume”、“$number\u of \u pages”、“$source”、“$cost”、“$quantity”、“$note”、“$category”
如何在不启用错误报告的情况下获取错误?请使用mysqli而不是mysql@programming学生使用post方法后仍不工作。打印SQL和将其粘贴到您的问题中。现在出现以下错误:“警告:mysqli_query()至少需要2个参数,1个参数在第21行的C:\xampp\htdocs\School Management\Untitled-1.php中给出”@SMRITIC Technologies,我根据您的错误编辑了我的答案。请用我在编辑中发布的代码替换您的部分代码。原始代码中的$sql=mysqli\u查询在哪里?您在问题中发布了不同的代码,这给每个人都造成了困惑!!!@user3806613不,事实上,在所有人的帮助下,我没有任何困惑欧..我在原始代码中进行了更改,并在上面再次发布。就是这样。即使感谢你们所有人在这方面的帮助。当您对原始代码进行更改时,您需要在问题中更新原始代码,以便其他人可以看到您所做的操作,以便他们能够相应地提供帮助。正如我所说,在原始代码中,您使用了mysql,但在回答中,yo你已经发布了,你已经使用了mysqli,而且你从来没有提到过你在原始代码中做了更改,这造成了混乱。祝你好运