【发布时间】:2015-01-08 06:11:58
【问题描述】:
警告:mysql_real_escape_string() 期望参数 1 是字符串,资源在 E:\wamp\www\inventory\admin\dashboard\insert_export.php 第 94 行中给出
我理解错误,但如何纠正错误,谁能给我解释一下。
<?php
include 'connection/db_connection.php';
$row_data = array();
foreach($_POST['productname'] as $row=>$productname) {
$date=$_POST['datetime'];
$subject=$_POST['subject'];
$productname=mysql_real_escape_string($con,$productname);
$itemcode=mysql_real_escape_string($con,($_POST['itemcode'][$row]));
$quantity=mysql_real_escape_string($con,($_POST['quantity'][$row]));
$row_data[] = "('$date','$productname', '$itemcode', '$quantity','$subject')";
}
if (!empty($row_data))
{
$sql = 'INSERT INTO admin_export(datetime, product_name, item_code,quantity,subject) VALUES '.implode(',', $row_data);
$result = mysql_query($sql );
if ($result)
echo 'Successful inserts: ' . mysql_affected_rows($con);
else
echo 'query failed' ;
}
?>
【问题讨论】:
-
应该像
$productname=mysql_real_escape_string($productname,$con);