我正在尝试将数据插入在phpmyadmin xampp服务器中创建的mysql数据库的表中。我正在使用php和html编码。连接成功,但是当我添加元素时,它显示“未插入数据”消息。 下面是我的代码:
<?php
$user = 'root';
$pass = '';
$db = 'sample';
$reg_no="reg_no";
$name="name";
$address="address";
$state="state";
$db = new mysqli('localhost',$user,$pass, $db) or die("Unable to connect");
if(isset($_POST['insert']))
{
$insert_Query="INSERT INTO sample_tab (reg_no,name,address,state)VALUES('$reg_no','$name','$address','$state')";
$insert_Result=mysqli_query($db,$insert_Query);
if(mysqli_affected_rows($db)>0)
{
echo'Data Inserted';
}else{
echo'Data not inserted';
}
}
mysqli_close($db);
?>
<html>
<head>
<title>PHP insert update and delete records.</title>
</head>
<body>
<form action="connect.php" method="post">
<input type="number" name="reg_no" placeholder="reg no" value="<?php echo $reg_no?>"><br><br>
<input type="text" name="name" placeholder="name"value="<?php echo $name?>"><br><br>
<input type="text" name="address" placeholder="address"value="<?php echo $address?>"><br><br>
<input type="text" name="state" placeholder="state"value="<?php echo $state?>"><br><br>
<div>
<input type="submit" name ="insert" value ="Add">
<input type="submit" name ="update" value ="Update">
<input type="submit" name ="delete" value ="Delete">
<input type="submit" name ="search" value ="Search">
</div>
</form>
</body>
</html>
请帮我解决这个问题。