这里我有用于连接和向数据库插入数据的php代码。 tfs.php: -
Electron
这是html代码: -
<?php
require "init.php";
$fsname = $_POST['fsname'];
$lsname =$_POST['lsname'];
$contact =$_POST['contact'];
$password =$_POST['password'];
$rent_on =$_POST['rent_on'];
$room_status =$_POST['room_status'];
$room_for =$_POST['room_for'];
$quantity =$_POST['quantity'];
$beds_status =$_POST['beds_status'];
$study_table =$_POST['study_table'];
$wifi =$_POST['wifi'];
$gizer =$_POST['gizer'];
$city =$_POST['city'];
$area =$_POST['area'];
$college =$_POST['college'];
$mail_id =$_POST['mail_id'];
$address =$_POST['address'];
$pcode =$_POST['pcode'];
$geo =$_POST['geo'];
$sql = "INSERT INTO `user_record`(`fsname`,`lsname` , `rent_on`,`room_status`,`city`,`area`,`college`,`room_for`,`quantity`,`beds_status`,`study_table`,`wifi`,`gizer`,`contact`,`password`,`mail_id`,`address`) VALUES ('$fsname','$lsname','$rent_on','$room_status','$city','$area','$college','$room_for','$quantity','$beds_status','$study_table','$wifi','$gizer','$contact','$password','$mail_id','$address')";
if(mysqli_query($con,$sql))
{
echo "<br><h3> Data submitted....</h3>";
}
else
{
echo "Error in insertation..." . mysqli_error($con);
}
?>
the status of connection is successful but showing the error.
这是数据库的结构: - the database contain 11 fields,when i will change the default values of pcode, geo, rent. 然后data inserted but some field shows empty and some are NULL.
所以我现在不知道该怎么做。给出解决这个问题的方法。
答案 0 :(得分:0)
检查HTML页面中分配的名称是否与PHP中的$ _POST相关联。
例如:
$room_status =$_POST['room_status'];
HTML页面中没有字段。
答案 1 :(得分:0)
您忘记了插入查询中的一些字段sno,pcode,geo&amp;租金,你的帖子应该是:
$room_status =$_POST['status'];
$room_for =$_POST['rent_for'];
$beds_status =$_POST['bed'];
$study_table =$_POST['s_table'];
查询:
$sql = "INSERT INTO `user_record`(`sno`,`fsname`,`lsname` , `rent_on`,`room_status`,`city`,`area`,`college`,`room_for`,`quantity`,`beds_status`,`study_table`,`wifi`,`gizer`,`contact`,`password`,`mail_id`,`address`,`pcode`,`geo`,`rent`) VALUES (NULL,'$fsname','$lsname','$rent_on','$room_status','$city','$area','$college','$room_for','$quantity','$beds_status','$study_table','$wifi','$gizer','$contact','$password','$mail_id','$address','$pcode','$geo','rent')";
您的代码是开放的SQL注入,使用预准备语句,清理您的变量,不要忘记保护您的密码
答案 2 :(得分:0)
INSERT INTO tbl (col1,col2) VALUES ('col1','col2');
)但是,您的表格具有col3,表格设置为create table tbl (col1 id not null auto_increment, col2 varchar(5), col3 boolean)
。当您在当前查询中插入时,假设您在pcode(col3)中有一个默认值,因为您拒绝在列声明中提供它。 答案 3 :(得分:0)
您可以尝试插入语句,并轻松检查每个变量的值
$sql = "INSERT INTO `user_record` SET
`fsname` = '".$fsname."',
`lsname` = '".$lsname."',
`rent_on` = '".$rent_on."'........