doumianfeng6979 2014-12-03 15:23
浏览 72

插入MySQL无法正常工作

This is a simple shopping cart I found somewhere, a long time ago and now in need of to make an ordering system of. But it for some or other bizarre reason not insert all of the fields I feed it!

My functions below:

function get_categoryid($pid){
$result=mysql_query("select product_category_id from shopping_products where serial=$pid") or die("select product_category_id from shopping_products where serial=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['product_category_id'];
}
 function get_thecategory($pid){
$result=mysql_query("select product_category_title from shopping_products where serial=$pid") or die("select product_category_title from shopping_products where serial=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['product_category_title'];
 }
}

Here is the PHP code where it gets inserted into the "shopping_order_detail" table after the clients has filled in his/her info.

if ( isset($_REQUEST['command']) && $_REQUEST['command']=='update'){
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $address=$_REQUEST['address'];
    $phone=$_REQUEST['phone'];
    $loyalty=$_REQUEST['loyalty'];

    $result=mysql_query("insert into shopping_customers values('','$name','$email','$address','$phone','$loyalty')");
    $customerid=mysql_insert_id();
    $date=date('Y-m-d');
    $result=mysql_query("insert into shopping_orders values('','$date','$customerid')");
    $orderid=mysql_insert_id();

    /* ---- below my problem i think --- */
    $max=count($_SESSION['cart']);
    for($i=0;$i<$max;$i++){
        $pid=$_SESSION['cart'][$i]['productid'];
        $q=$_SESSION['cart'][$i]['qty'];
        $price=get_price($pid);
        $pcategoryid=get_categoryid($pid);
        $pcategory=get_thecategory($pid);
        $pvendor=get_thevendor($pid);

        mysql_query("INSERT INTO shopping_order_detail VALUES($orderid,$pid,$q,$price,$pcategoryid,$pcategory,$pvendor)");

    echo "vendor -" . $pvendor . "  Order ID - " . $orderid . " - Product ID - " . $pid . " - Category ID ". $pcategoryid ." - Price R ". $price .".00  - Quantity ". $q. "- Category Title: ". $pcategory ."<Br>";
    }
    echo "<br>=======================================================================================<br>";
    echo "<br>Data echoed above this works fine.. and pulls the correct shopping items<br>";
    echo "<br>Sucess ......Data Inserted!<br>";
    die('Thank You! your order has been placed');
}

Here is my problem !

The "$pcategoryid" is inserted into the table , But whatever amount of fields i ad after this not only does not insert, but it also for some or other reason prevent any information being inserted with this piece of script.

To recap my problem: If I remove "$pcategory" and "$pvendor" from the script the data gets inserted. if I add these two fields in question then the script does not insert, But/And it does not give any error messages.

My "Echo === etc" commands at the bottom of the script shows me that my script is working as it shows those two fields in question when it cycles through list of items

I have set my PHP error codes this way:

 ini_set('display_errors',1);
 ini_set('display_startup_errors',1);
 error_reporting(-1);

Is it some kind of restriction in Mysql as the Table in question does not have a primary key? I am at a loss for a solution!

Please, Any help will be appreciated thank you.

  • 写回答

2条回答 默认 最新

  • dongpao5658 2014-12-03 15:33
    关注

    Try this

    $result=mysql_query("insert into shopping_customers values('$name','$email','$address','$phone','$loyalty')");

    And

    $result=mysql_query("insert into shopping_orders values('$date','$customerid')");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分