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 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值