时间:2021-07-01 10:21:17 帮助过:28人阅读
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语句输入的差数有问题.已解决,版主帮忙把帖删了,谢谢!