//database class
class dbmgmt{
public $tbl_name;
public $field_arr;
public $val_arr;
public $cond_arr;
function execute($sql){
global $conn;
$result=$conn->query($sql);
if(!$result) echo "Error: ".$conn->error;
}
function insert(){
$sql="INSERT INTO ".$this->tbl_name." SET ";
for($i=0;$i++;$i<count($this->field_arr)){
if($i!=(count($this->field_arr)-1)){
$sql.=$this->field_arr[i]."=".$this->val_arr.",";
}else{
$sql.=$this->field_arr[i]."=".$this->val_arr;
}
}
$this->execute($sql);
}
}
$ado=new dbmgmt();
//admin_add.php
$ado->tbl_name="tbl_admin";
$ado->field_arr=array("username","password",'type','email');
$ado->val_arr=array($username,create_hash($password),$admin_type,$email);
$ado->insert();
if($conn->connect_error){
die("Failed to add Record: ".$conn->connect_errno. ' '.$conn->connect_error);
}else{
echo "Succesfully Added Record";
echo "<script>window.location=".ADMIN_PAGE."</script>";
}
我不斷收到此錯誤:MySQL總是給人SQL語法錯誤
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.
我到底做錯了什麼?
查詢在執行之前的樣子是怎樣的? –
你正在用'SET'編寫'INSERT'查詢嗎?是否corretc –
'SET'可以用於'INSERT' http://dev.mysql.com/doc/refman/5.6/en/insert.html –