+ -
当前位置:首页 → 问答吧 → 关于php插入数据库却不执行的问题,高手请进,谢谢

关于php插入数据库却不执行的问题,高手请进,谢谢

时间:2008-03-12

来源:互联网

今天一直在写一个php语言,主要是用于数据库添加,但是数据都能从post获取,在插入却不执行,没找到问题所在,我把代码贴上来,大家帮我看下什么地方有问题

PHP code
 
<?php
require_once("hp1_conn.php");

$goods=$_POST['goods'];//商品名称
$bn=$_POST['bn'];//货号
$intro=$_POST['intro'];//简单描述
$danwei=$_POST['danwei'];//计量单位
$weight=$_POST['weight'];//单位重量
$storage=$_POST['storage'];//库存数量

$smallimgremote=$_POST['smallimgremote'];//缩略图远程链接地址
$bigimgremote=$_POST['bigimgremote'];//清晰图远程链接地址

$priceintro=$_POST['priceintro'];//市场价
$price=$_POST['price'];//会员价格
$point=$_POST['point'];//积分
$basicprice=$_POST['basicprice'];//成本价格
$memo=$_POST['content'];//详细介绍

$cat=$_POST['catid'];//分类
$catsql="SELECT * FROM `sdb_mall_offer_pcat` WHERE `cat`='$cat'";
$catresult=mysql_query($catsql);
$catarray=mysql_fetch_array($catresult);
$catid=$catarray[catid];

$brand=$_POST['brand'];//品牌名
$brandsql="SELECT * FROM `sdb_mall_brand` WHERE `brand_name`='$brand'";
$brandresult=mysql_query($brandsql);
$brandarray=mysql_fetch_array($brandresult);
$brand_id=$brandarray[brand_id];//品牌id

//存入图片的路径
$uploaddir="syssite/home/shop/1/pictures/productsimg/small/";

//存入图片的前缀
for($j=0;$j <=9;$j++){
srand((double)microtime()*1000000);
$randname=rand(!$j ? 1: 0,9);//产生随机数,不以0为第一个数,有些特殊的地方0开头被系统省略
$picadd.=$randname;
}

//验证,如果有图片传入,则给图片加上相应前缀和路径,uploadfile是给移动图片函数用的,$smallimgremote是给数据传入用的,两个路径不同
if($_FILES['picfile']['name']!=""){
$picname = $picadd.$_FILES['picfile']['name'];
$uploadfile = $uploaddir.$picname;
$smallimgremote = $uploaddir.$picname;
}else{
$uploadfile="";
$smallimgremote="";
}

//验证文件类型并用移动图片函数移动
if($_FILES['picfile']['type']=jpg||$_FILES['picfile']['type']=gif||$_FILES['picfile']['type']=bmp||$_FILES['picfile']['type']=png){
move_uploaded_file($_FILES['picfile']['tmp_name'],$uploadfile);
}else{
echo " <script>alert('请上传图片!') </script>";
}

echo " <table> <tr> <td>商品名称: </td> <td>$goods </td> </tr>
<tr> <td>商品货号: </td> <td>$bn </td> </tr>
<tr> <td>简单描述: </td> <td>$intro </td> </tr>
<tr> <td>计量单位: </td> <td>$danwei </td> </tr>
<tr> <td>单位重量: </td> <td>$weight </td> </tr>
<tr> <td>库存数量: </td> <td>$storage </td> </tr>
<tr> <td>缩略图远程链接地址: </td> <td>$smallimgremote </td> </tr>
<tr> <td>清晰图远程链接地址: </td> <td>$bigimgremote </td> </tr>
<tr> <td>市场价: </td> <td>$priceintro </td> </tr>
<tr> <td>会员价格: </td> <td>$price </td> </tr>
<tr> <td>积分: </td> <td>$point </td> </tr>
<tr> <td>成本价格: </td> <td>$basicprice </td> </tr>
<tr> <td>分类名: </td> <td>$cat </td> </tr>
<tr> <td>分类id: </td> <td>$catid </td> </tr>
<tr> <td>品牌名: </td> <td>$brand </td> </tr>
<tr> <td>品牌id: </td> <td>$brand_id </td> </tr>
<tr> <td>详细介绍: </td> <td>$memo </td> </tr>
</table>";


$sql="INSERT INTO `sdb_mall_goods` ( `gid` , `offerid` , `catid` , `mcatid` , `bn` , `goods` , `memo` , `intro` , `brand` , `danwei` , `priceintro` , `price` , `storage` , `pendstorage` , `mall_iffb` , `shop_iffb` , `offer_ord` , `mall_ord` , `rq` , `recommand1` , `recommand2` , `hot1` , `hot2` , `tejia1` , `tejia2` , `new2` , `uptime` , `ifobject` , `ifalarm` , `alarmnum` , `point` , `digital_file` , `attr1` , `attr2` , `attr3` , `attr4` , `attr5` , `attr6` , `attr7` , `attr8` , `attr9` , `attr10` , `linkclass` , `wholesale_scheme` , `ifdiscreteness` , `smallimgremote` , `bigimgremote` , `multi_image` , `attr11` , `attr12` , `attr13` , `attr14` , `attr15` , `attr16` , `attr17` , `attr18` , `attr19` , `attr20` , `attr21` , `attr22` , `attr23` , `attr24` , `attr25` , `attr26` , `attr27` , `attr28` , `attr29` , `attr30` , `attr31` , `attr32` , `attr33` , `attr34` , `attr35` , `attr36` , `attr37` , `attr38` , `attr39` , `attr40` , `weight` , `smallwsize` , `smallhsize` , `bigwsize` , `bighsize` , `linkgoods` , `attrmark` , `basicprice` , `su_category` , `su_catname` , `su_sync` , `last_modified` , `meta_description` , `meta_keywords` , `title` , `costprice` , `onsale` , `point_consume_method_value` , `point_consume_method_percent` , `point_consume_method` , `brand_id` , `strtag` , `param_table` , `visit_ct` )
VALUES (
NULL, '1', '$catid', '0', '$bn', '$goods', '$memo', '$intro', '$brand', '$danwei', '$priceintro', '$price' , '$storage', '0', '1', '1', '1', '1', NULL , '0', '0', '0', '0', '0', '0', '1', UNIX_TIMESTAMP( ) , '1', '0', '0', '0', NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , '0', '0', '$smallimgremote', '$bigimgremote', NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , '$weight', '0', '0', '0', '0', NULL , NULL , '$price', '0', NULL , '1', '0', NULL , NULL , NULL , '$basicprice' , '1', '0', '0.00', 'value', '$brand_id', NULL , NULL , '0'
);";

mysql_query($sql);

echo "成功加入,请 <a href=hp1_goods.php>返回 </a>";

?>

作者: myth815   发布时间: 2008-03-12

PHP code

<?php


......
mysql_query($sql) or die("没有成功, 原因:".mysql_error());
echo "成功加入,请<a href=hp1_goods.php>返回</a>";
......
?>

作者: mrshelly   发布时间: 2008-03-12

1. 你那些NULL都在双引号里?
  如过是NULL, 忽略就是了,不过要记的在db里设好allow null
2. gid是autoincrement? 查下数据库是不是设对了

小建议:没必要都加`符号吧,要是每句sql都这么写,早疯了。

作者: timofuk   发布时间: 2008-03-12

我跟你碰到的问题一样,你解决了没有啊,我自己写着玩,写自己的BLOG,这里出错了,也是不能成功插入,
$result=mysql_query($sql,$server_link),执行这一句时出错,$result是空的,根本没有执行这一句话,真实无语了。

作者: willhuo   发布时间: 2011-09-06

能否只贴一小段代码和问题描述?

作者: phpunique   发布时间: 2011-09-06

相关阅读 更多

热门下载

更多