21,886
社区成员
发帖
与我相关
我的任务
分享
$db = mysql_connect('localhost','root','123456');
$query = "insert into {$comments_table} values (null,'{$username}','{$content}')";
$result = mysql_query($query, $db);
if ($result){
echo '提交成功';
}else{
echo '发生错误';
}
/**
* 数据库插入语句.$table为表名,$keyvalue为带key的数组,数组的key为字段,数组的value为插入的值
* 函数自动为插入字符串值加上单引号
*/
function mysql_insert($table,$keyvalue){
$key=implode(',',array_keys($keyvalue));
foreach($keyvalue as $tempkey=>$val){
if(is_string($val))$keyvalue[$tempkey]="'$val'";
}
$value=implode(',',$keyvalue);
$sql="insert into $table ($key) values ($value)";
mysql_query($sql) or die ("insert error");
}
if($_POST['submit']){
zlsky_post_trim();
$sql=new MySql();
$arr=array("product_spec"=>"$_POST[spec]","product_candi"=>"$_POST[producing_area]","product_price"=>$_POST[spread],"product_title"=>"$_POST[producttitle]","product_kind"=>"$_POST[productkind]","product_visible"=>"$_POST[visible]","product_content"=>"$_POST[gcontent]");
if (is_uploaded_file($_FILES["upfile"][tmp_name])){
include("inc/upfileclass.php");
$upfile=new upfile();
$upfile->upfile();
$arr['product_img']="$upfile->fname";
}
if($sql->mysql_insert('product',$arr)){
alert_msg("产品添加成功",1);
}else{
alert_msg("产品添加失败",1);
}
}