Heim >Backend-Entwicklung >PHP-Tutorial >插入数据库错误的问题?问题出在哪里?
数据库 exception
刚开始写留言板,通过mysqlconnect类的insert方法讲留言信息插入数据库public function insert($table_name, $data_array){ $field_array = array(); $value_array = array(); foreach($data_array as $k => $v){ $field_array[] = $k; if(gettype($v) != "integer"){ $value_array[] = "'".$v."'"; }else{ $value_array[] = $v; } } $sql = "insert into ".$table_name."(".implode(",",$field_array).") values(".implode(",",$value_array).")"; //echo $sql; //exit(); $boolean = $this->execute($sql); $this->insertId = mysql_insert_id($this->connection); return $boolean; }
$vname = $_POST["name"]; $vcontent = $_POST["content"]; $vaddtime = date("Y-m-d h:i:s"); $vreply = ""; $arr = array("name"=>$vname,"addtime"=>$vaddtime,"content"=>$vcontent,"reply"=>$vreply); $message = new message; $done = $message->insert("message", $arr);
不好意思,SQL语句输入的差数有问题.已解决,版主帮忙把帖删了,谢谢!