猿问

慕课商品添加,插入不进数据库


/**

 * 添加商品

 * @return string

 */

function addPro(){

$arr=$_POST;

$arr['addtime']=time();

$path="./uploads";

$uploadFiles=uploadFile($path);

if(is_array($uploadFiles)&&$uploadFiles){

foreach($uploadFiles as $key=>$uploadFile){

thumb($path."/".$uploadFile['name'],"../image_50/".$uploadFile['name'],50,50);

thumb($path."/".$uploadFile['name'],"../image_220/".$uploadFile['name'],220,220);

thumb($path."/".$uploadFile['name'],"../image_350/".$uploadFile['name'],350,350);

thumb($path."/".$uploadFile['name'],"../image_800/".$uploadFile['name'],800,800);

}

}

$res=insert("store",$arr);

print_r(res);die;           // 插入数据打印的是 0   

$pid=getInsertId();

if($res&&$pid){

foreach($uploadFiles as $uploadFile){

$arr1['pid']=$pid;

$arr1['imageAddr']=$uploadFile['name'];

addAlbum($arr1);

}

$mes="<p>添加成功!</p><a href='addPro.php' target='mainFrame'>继续添加</a>|<a href='listPro.php' target='mainFrame'>查看商品列表</a>";

}else{

if(is_array($uploadFiles)&&$uploadFiles){

foreach($uploadFiles as $uploadFile){

if(file_exists("../image_800/".$uploadFile['name'])){

unlink("../image_800/".$uploadFile['name']);

}

if(file_exists("../image_50/".$uploadFile['name'])){

unlink("../image_50/".$uploadFile['name']);

}

if(file_exists("../image_220/".$uploadFile['name'])){

unlink("../image_220/".$uploadFile['name']);

}

if(file_exists("../image_350/".$uploadFile['name'])){

unlink("../image_350/".$uploadFile['name']);

}

 }

}

$mes="<p>添加失败!</p><a href='addPro.php' target='mainFrame'>重新添加</a>";

}

return $mes;

}


慕丝5297831
浏览 1083回答 1
1回答

qq_阿湃_0

看下 insert 方法,是不是有问题(数据重复约束;数据字段名,字段类型,非空数值等)。
随时随地看视频慕课网APP
我要回答