le 06/09/2011 à 18:50
Aide class php
user_DB.php
insert.php
Formulaire
<form method="post" action="insert.php">
Nom : <input type="text" id="fname" name="fname" size="20" maxlength="50" /><br />
Prénom : <input type="text" id="lname" name="lname" size="20" maxlength="50" /><br />
Email : <input type="text" id="email" name="email" size="50" maxlength="100" /><br />
password : <input type="text" id="password" name="password" size="20" maxlength="50" /><br />
<input type="submit" value="Save" />
</form>
Parse error: syntax error, unexpected T_PUBLIC in insert.php on line 4
J'ai essayé de nouveau comme ceci et ça ne fonctionne toujours pas
<?php
require_once 'config.php';
class DB {
private static $_instance;
public function &pdo_connection(){
if(!self::$_instance){
try {
self::$_instance = new PDO(DSN,USERNAME,PASSWORD);
self::$_instance->setAttribute(PDO::ATTR_PERSISTENT, true);
self::$_instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $est) {
die("pdo connection error! ". $est->getMessage() ."<br/>");
}
}
return self::$_instance;
}
private function __construct() {
}
private function __clone() {}
}
class user extends DB {
private $db_connect= "";
public $id, $fname, $lname, $email, $password, $admin_id, $create_date, $enable;
public function __construct() {
$this->db_connect = $this->pdo_connection();
}
public function __destruct() {
$this->db_connect = null;
}
}
?>
insert.php
<?php
require_once 'user_DB.php';
public function insert(){
try {
if($this->checkExistEmail())
{
echo "User is already existed" . "<br/>";
return false;
}
else{
if(isset($this->fname) && isset($this->lname) && isset($this->email) && isset($this->password))
{
$query = 'INSERT INTO user
SET u_fname=:fname,
u_lname=:lname,
u_email=:email,
u_password=PASSWORD(:password),
u_create_date=now()';
$sql_statement = $this->db_connect->prepare($query);
$sql_statement->bindParam(':fname',$this->fname,PDO::PARAM_STR);
$sql_statement->bindParam(':lname',$this->lname,PDO::PARAM_STR);
$sql_statement->bindParam(':email',$this->email,PDO::PARAM_STR);
$sql_statement->bindParam(':password',$this->password,PDO::PARAM_STR);
if(!$sql_statement->execute()) {
return false;
}
return true;
}
else {
return false;
}
}
}
catch(PDOException $e){
echo "error! can't insert into the user information" . $e->getMessage() . "<br/>";
return false;
}
}
?>
Formulaire
<?php
require_once 'user_DB.php';
?>
<form method="post" action="insert.php">
Nom : <input type="text" id="fname" name="fname" size="20" maxlength="50" /><br />
Prénom : <input type="text" id="lname" name="lname" size="20" maxlength="50" /><br />
Email : <input type="text" id="email" name="email" size="50" maxlength="100" /><br />
password : <input type="text" id="password" name="password" size="20" maxlength="50" /><br />
<input type="submit" value="Save" />
</form>
Parse error: syntax error, unexpected T_PUBLIC in insert.php on line 4
J'ai essayé de nouveau comme ceci et ça ne fonctionne toujours pas