<?php
Class User
{
private $errormessage = "";
public function signup($POST)
{
$data = array();
$db = Dbconnect::getInstance();
$data['$user_firstname'] = trim($POST['sig_user_firstname']);
$data['$user_lastname'] = trim($POST['sig_user_lastname']);
$data['$user_email'] = trim($POST['sig_user_email']);
$data['$user_pass'] = trim($POST['sig_user_pass']);
$user_pass2 = trim($POST['sig_user_pass2']);
$data['$user_phone_num'] = trim($POST['sig_user_phone_num']);
if(empty($data['$user_email']) || !preg_match("/^[a-zA-Z_-]+@[a-zA-Z]+.[a-zA-Z]+$/", $data['$user_email']))
{
$this->errormessage .= "Please enter a valid email.";
}
if(empty($data['$user_firstname']) || !preg_match("/^[a-zA-Z]+$/", $data['$user_firstname']))
{
$this->errormessage .= "Please enter a valid first name.";
}
if(empty($data['$user_lastname']) || !preg_match("/^[a-zA-Z]+$/", $data['$user_lastname']))
{
$this->errormessage .= "Please enter a valid last name.";
}
if($data['$user_pass'] !== $user_pass2)
{
$this->errormessage .= "The password does not match.";
}
if(strlen($data['$user_pass']) < 5)
{
$this->errormessage .= "The password must be at least 5 characters long.";
}
if($this->errormessage == "")
{
$data['user_type'] = "customer";
$data['user_id_url'] = $this->get_random_string(60);
show($result);
$query = "insert into user (user_id_url, user_firstname, user_lastname, user_email, user_pass, user_phone_num, user_type) values (:user_id_url, :user_firstname, :user_lastname, :user_email, :user_pass, :user_phone_num, :user_type)";
$result = $db->write($query,$data);
if($result)
{
header("Location: ". ROOT ."login");
die;
}
}
}
public function login($POST)
{
}
public function get_user($url)
{
}
private function get_random_string($strlen)
{
$ranArray = array('!','@','#','$','%','^','&','*','(',')',0,1,2,3,4,5,6,7,8,9,'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M');
$rantext="";
$strlen = rand(4,$strlen);
for ($i=0; $i < $strlen; $i++)
{
$rankey = rand(0,61);
$rantext .= $ranArray[$rankey];
}
return $rantext;
}
}
<?php
Class Dbconnect
{
public static $conn;
public function __construct()
{
try
{
$str = DB_TYPE . ":host=" . DB_HOST . ";dbname=" . DB_NAME;
self::$conn = new PDO($str,DB_USER,DB_PASS);
}
catch (PDOException $error)
{
die($error->getMessage());
}
}
public static function getInstance()
{
if(self::$conn)
{
}
return $instance = new self();
}
public static function newInstance()
{
return $instance = new self();
}
public function read($query, $data = array())
{
$statem = self::$conn->prepare($query);
$result = $statem->execute($data);
if($result)
{
$data = $statem->fetchAll(PDO::FETCH_OBJ);
if(is_array($data))
{
return $data;
}
}
return false;
}
public function write($query, $data = array())
{
$statem = self::$conn->prepare($query);
$result = $statem->execute($data);
if($result)
{
return true;
}
return false;
}
}
The error occurs when I tried to insert values into MySQL database
What I have tried:
I have tried changing the value names but no luck.