dsgdf45654 2012-09-07 18:34
浏览 72
已采纳

警告:mysql_real_escape_string()期望参数1为字符串

HTML CODE

<tr>
   <td><input type="text" name="batch_code[]" required="required" value="<?php      if(isset($batch_code[0]))echo htmlentities($batch_code[0]); ?>"/></td>
   <td><input type="text" name="description[]" value="<?php if(isset($description[0]))echo htmlentities($description[0]); ?>"/></td>
   <td><input type="text" name="current_value[]" value="<?php if(isset($current_value[0]))echo htmlentities($current_value[0]); ?>"/></td>
   <td><input type="text" size="12" name="qty[]"  required="required"  value="<?php if(isset($qty[0]))echo htmlentities($qty[0]); ?>"/></td>
   <td><select id="asset_id" class="asset_id" name="asset_id[0][]" multiple="multiple" required>
    <?php foreach($asset_ids as $asset_id): ?>
            <option class="dropdownlist"><?php echo $asset_id->asset_id; ?></option> 
     <?php endforeach; ?>
    </select></td>
</tr>
<tr>
   <td><input type="text" name="batch_code[]" required="required" value="<?php      if(isset($batch_code[1]))echo htmlentities($batch_code[1]); ?>"/></td>
   <td><input type="text" name="description[]" value="<?php if(isset($description[1]))echo htmlentities($description[1]); ?>"/></td>
   <td><input type="text" name="current_value[]" value="<?php if(isset($current_value[1]))echo htmlentities($current_value[1]); ?>"/></td>
   <td><input type="text" size="12" name="qty[]"  required="required"  value="<?php if(isset($qty[1]))echo htmlentities($qty[1]); ?>"/></td>
   <td><select id="asset_id" class="asset_id" name="asset_id[1][]" multiple="multiple" required>
    <?php foreach($asset_ids as $asset_id): ?>
            <option class="dropdownlist"><?php echo $asset_id->asset_id; ?></option> 
     <?php endforeach; ?>
    </select></td>
</tr>

And My php codes are

$count = count(array_filter($this->asset_id))-1;
for($value = 0; $value <= $count; $value++){
    $count_asset = count(array_filter($this->asset_id))-1;
    for($asset_value = 0; $asset_value <= $count_asset; $asset_value++){
        $sql  = "INSERT INTO dispatch_items (";
        $sql .= "dis_id, batch_code, asset_id, description, current_value, qty";
        $sql .= ") VALUES ('";
        $sql .= $database->escape_value($this->dis_id) ."', '";
        $sql .= $database->escape_value($this->batch_code[$value])."', '";
        $sql .= $database->escape_value($this->asset_id[$value][$asset_value]) ."', '";
        $sql .= $database->escape_value($this->description[$value]) ."', '";
        $sql .= $database->escape_value($this->current_value[$value]) ."', '";
        $sql .= $database->escape_value($this->qty[$value]) ."')";
        $query = $datanase->query($sql);
        $sql  = "UPDATE asset_manager SET ";
        $sql .= "location='".$database->escape_value($this->rstore_code)."', ";
        $sql .= "dis_id='".$database->escape_value($this->dis_id)."' ";
        $sql .= "WHERE asset_id='".$database->escape_value($this->asset_id[$value][$asset_value])."' ";
        $sql .= "AND batch_code='".$database->escape_value($this->batch_code[$value])."' ";
        $query = $database->query($sql);
    }
}

I'm trying insert multiple form data to database and give option to user select multiple asset_id[][] for every batch_code[] but when inset it to database keep getting this error.. :(

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in D:\assetmanagement\includes\database.php on line 52

public function escape_value( $value ) {
      if( $this->real_escape_string ) { // PHP v4.3.0 or higher
     // undo any magic quote effects so mysql_real_escape_string can do the work
     if( $this->magic_quotes_active ) { $value = stripslashes( $value ); }
         $value = mysql_real_escape_string( $value );\\ line 53
     } else { // before PHP v4.3.0
         // if magic quotes aren't already on then add slashes manually
         if( !$this->magic_quotes_active ) { $value = addslashes( $value ); }
         // if magic quotes are active, then the slashes already exist
     }
    return $value;
}

How can i fix this error..?

  • 写回答

1条回答 默认 最新

  • dtvhqlc57127 2012-09-07 18:40
    关注

    Instead of using

    if( $this->real_escape_string ) { // PHP v4.3.0 or higher
    

    check php version with

    phpversion()
    

    or

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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测