mysql数据会显示“数组"在表格列中 [英] Mysql data will show "Array" in table column

查看:39
本文介绍了mysql数据会显示“数组"在表格列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想问一下我的 php 编码..
我正在做一些数组编码,但是当我提交我的数据时,在我的数据库中将在描述"和数量"列中显示一个数组..
我用的mysql..下面是我的数组编码..


I want to ask about my php coding..
I'am doing some array coding but when I submit my data, in my database is will display an array at the 'description' and 'qty' column..
I use mysql.. Below is my array coding..

$item = array(
'item_description' => '',
'price' => '',
'qty' => '',
'amount' => '',
);
foreach ($item as $key => $value){
$item_description = $_POST['item_description'][$key];
$price = $_POST['price'][$key];
$qty = $_POST['qty'][$key];
$amount = $_POST['amount'][$key];}
}

这是我的插入查询.

$sql1="INSERT INTO payment_item (payment_id, payment_item_id, item_description, price, qty, amount)
VALUES
('$last_insert_payment_id','NULL','$_POST[item_description]','$_POST[price]','$_POST[qty]','$_POST[amount]')";

这是我的表格:

<form>
<h1>Payment Item</h1>
Payment ID :<input id="payment_id" name="payment_id" type="text"><br>
<input type="button" value="Add Row" onClick="addRow('tableID')"/>
<input type="button" value="Delete Row" onClick="deleteRow('tableID')"/>
<table class="table" bgcolor="#CCCCCC">
<thead>
<tr>
<td></td>
<td><center>Item Description</center></td>
<td><center>Price (RM)</center></td>
<td><center>Month</center></td>
<td><center>Amount (RM)</center></td>
</tr>
</thead>
<tbody id="tableID">
<tr>
<td><input type="checkbox" name="chk"></td>
<td>
<select name="item_description">
    <option value="deposit">Deposit</option>
    <option value="rental">Rental</option>
    <option value="stamp">Stamp Duty</option>
    <option value="process">Process Fee</option>
    <option value="ap">AP</option>
</select>
</td>
<td><input id="price" name="price" type="text"></td>
<td><input id="month" name="qty" type="text"></td>
<td><input id="amount" name="amount" type="text"></td>
</tr>
</tbody>
</table>
<input name="submit" type="submit" value="Submit">
<input name="reset" type="reset" value="Reset">
</form>

我很抱歉我的英语不好..
但我真的需要有人为此提供帮助..
谢谢..

I'am sorry for my poor english language..
But I really need any help from someone for this..
Thank you..

推荐答案

当 PHP 尝试将数组转换为字符串时,会出现一个词 'Array'.
因此,对于显示为 Array 的字段,您必须以某种方式处理它,这取决于您的应用程序逻辑,将您拥有的任何数组转换为正确的字符串.

A word 'Array' appears when PHP is trying to cast an array as a string.
So for the field appeared as Array you have to process it somehow, depends on your application logic, converting whatever array you have to a proper string.

这个问题与mysql无关.

The question has nothing to do with mysql though.

还要记住,您必须格式化 SQL 字符串.至少做

Also remember that you have to format your SQL strings. At the very least do

$var = mysql_real_escape_string($var);

对于您要放入查询中的每个变量,并将其用单引号括在查询中.

for the every variable you're putting into query, and wrap it single quotes in the query.

这篇关于mysql数据会显示“数组"在表格列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆