I make a simple HTML form and insert data in PHP through class I am new in PDO class so have no idea for insert data in the database and my PHP code is that
<?php
if(isset($_POST['submit']))
{
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$mnumber=$_POST['mnumber'];
$status=1;
// configuration of php and database connection
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'test');
class DB_con
{
function __construct()
{
$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
$this->dbh=$con;
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
}
public function insert($fname,$lname,$contact,$email,$mnumber,$status)
{
$ret=mysqli_query($this->dbh,"user (`FirstName`, `LastName`, `EmailId`, `ContactN`, `Status`) VALUES ('$fname','$lname','$email','$mnumber','$status')");
return $ret;
}
}
}
?>
Aucun commentaire:
Enregistrer un commentaire