doulian7252 2012-03-28 22:20
浏览 43
已采纳

将数据解析为序列化数组会产生标量值警告和致命字符串偏移

I am trying to parse data into a serialized array but can't figure it out and it errors out. What I am trying to do is utilize update_post_meta to fill in the serialized array with values that will be parsed to it.

example output of the array:

get_post_meta('840', '_eshop_product',true ); 


(
[sku] => 1234567885 
[products] => 
Array 
( 
    [1] => Array 
    ( 
        [option] => Retail 
        [price] => 3.99 
        [tax] => 1 
        [saleprice] =>
     )
 ) 
[description] => Astonishing X-men 
[shiprate] => A 
[featured] => Yes 
[sale] => yes 
[cart_radio] => 0 
[optset] => 
)

All i can find for resources is examples of get_post_meta and I'm trying to utilize update_post_meta to parse new data into these fields. Here's the code:

$meta2 = update_post_meta($post_id, '_eshop_product', true);
$meta3 = update_post_meta;
$meta3($post_id, '_eshop_stock', true); //works

$meta2['sku']=htmlspecialchars($_POST['eshop_sku']); //this is line 90
if($meta2['sku']=''){update_post_meta($meta2['_sku'], "{$id}");} //this is line 91

$numoptions=$eshopoptions['options_num'];
for($i=1;$i<=$numoptions;$i++)
{
    $meta2['products'][$i]['option']=htmlspecialchars($_POST['eshop_option_'.$i]); //this is line 96
    if($_POST['eshop_price_'.$i]='0'){update_post_meta($meta2($_POST['eshop_price_'.$i]), "{pricing_high}");}

    if($_POST['eshop_tax_'.$i]='No'){update_post_meta($meta2($_POST['eshop_tax_'.$i]), 'band 1');} //this is line 99
}

$meta2['description']=htmlspecialchars($_POST['eshop_product_description']);
if($meta2['description']==''){update_post_meta($meta2['description'], 'singles');}

$meta2['shiprate']=$_POST['eshop_shipping_rate'];
if($meta2['shiprate']='F'){update_post_data($meta2['_Shipping Rate'], 'A');}

if($_POST['eshop_sale_product']=='No'){update_post_meta( $id, '_eshop_sale', 'yes');}

And these are the errors that I get:

Warning: Cannot use a scalar value as an array in /home/***/public_html/wp-content/themes/***/mtgpage.php on line 90

Warning: Cannot use a scalar value as an array in /home/***/public_html/wp-content/themes/***/mtgpage.php on line 91

Warning: Cannot use a scalar value as an array in /home/***/public_html/wp-content/themes/***/mtgpage.php on line 96

Fatal error: Function name must be a string in /home/***/public_html/wp-content/themes/***/mtgpage.php on line 99

When I edit the product also in wordpress where the custom data would be located under the editor - there is an error and the custom fields will not display:

Fatal error: Cannot use string offset as an array in /home/***/public_html/wp-content/plugins/eshop/eshop-product-entry.php on line 44
  • 写回答

1条回答 默认 最新

  • duanhuangyun3887 2012-03-29 14:49
    关注

    There are a lot of errors there. The first 3 errors are regarding the function update_post_meta() which is not returning an array. So $meta2 is not an array and you cannot treat it like that. So check that function and be sure it is returning an array.

    Every if of your script, will return true. For example if($meta2['shiprate']='F') is always true because you are assigning $meta2['shiprate'] = to a string and the evaluated test is if ('F') which is true. You might be wanting to test the value of $meta2['shiprate'] then you have to use == like this: if($meta2['shiprate']=='F').

    For the last error, I don't exactly understand what you are trying to active here: $meta2($_POST['eshop_tax_'.$i]), but it is not a valid use of variable of variable attached to a string function name. You probably want to do $meta2[$_POST['eshop_tax_'.$i]].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了