register.class.php code
<?php
class DataBase
{
public $connection;
private $hostname;
private $username;
private $password;
private $db;
public function connect($host,$user,$pass,$dtb)
{
$this->hostname=$host;
$this->username=$user;
$this->password=$pass;
$this->db=$dtb;
return $this->connection=mysqli_connect($host,$user,$pass,$dtb) or die("Could not connect");
}
public function insert($fields,$data,$table)
{
try{
$queryfield=implode(",",$fields);
$queryvalues=implode('","',$data);
$sql='insert into '.$table.'('.$queryfield.') values("'.$queryvalues.'")';
if(mysqli_query($this->connection,$sql)
{
return TRUE;
}else{
die(mysqli_error($this->connection));
}
}catch(Exception $e){
echo "Error:" .$e;
}
}
}
?>
register.php code
<?php
include 'register.class.php';
$con=new DataBase();
$con->connect('localhost','root','ricky','mydatabase');
if(isset($_POST['submit']))
{
$uName=$_POST['username'];
$email=$_POST['email'];
$uPassword=$_POST['password'];
$passHash=crypt($uPassword);
$field=array('username','email','password');
$values=array($uName,$email,$passHash);
$res=$con->insert($field,$values,'users5');
if($res)echo"1 record inserted";
}
?>
form.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="register.php" method="post" enctype="multipart/form-data">
<label>NAME:</label><br>
<input type="text" name="username" required value=""><br><br>
<label>E-MAIL:</label><br>
<input type="text" name="email" required value=""><br><br>
<label>PASSWORD:</label><br>
<input type="password" name="password" required value=""><br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
unable to insert record page show blank without inserting record