سلام وقت بخیر
دو تا فایل دارم یکیش برا اتصال دیتابیس و یکیش هم کدهای افزودن به جدول . کدهاش بصورت زیر هست در phpadmin دیتابیس test جدول useruser ایجادکردم ولی با این کدها userثبت نمیشه لطفا بررسی کنید بنظر همه چی درست میاد
<?php
$servername="localhost";
$username="root";
$password="";
$dbname="test";
$con = new mysqli($servername, $username, $password, $dbname);
if (!$con) {
die(mysqli_error($con));
}
<?php
include("dbconnect.php");
global $con;
if(isset($_POST["submit"])) {
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$sql="insert into useruser(name, lastname,address) values ('$name','$lastname','$address')";
if(mysqli_query($con,$sql)){
echo "New record created successfully";
}
else{
die(mysqli_error($con));
}}
?>
کد HTML:
<html lang="en">
<head>
<title>Html Forms</title>
</head>
<body>
<h2>HTML Forms</h2>
<div class="container"
<form name="form" action="adduser.php" method="POST" >
<div class="mb-3">
<label for="name">Username:</label>
<input type="text" id="nametext" name="name">
</div>
<div class="mb-3">
<label for="lastname">lastname:</label>
<input type="text" id="lnametext" name="lastname">
</div>
<div class="mb-3">
<label for="address">address</label>
<input type="text" id="addresstext" name="address">
</div>
<button type="submit">submit</button>
</form>
</body>