将数组字符串值插入数据库单个字段而不是id

时间:2014-05-23 11:19:00

标签: php mysql

$lid= mysql_insert_id();

 $lid= mysql_insert_id();                  
$cityid = trim(ucwords(strtolower(mysql_real_escape_string($_POST['city']))));

$ids = array();
foreach($_POST['place'] as $val)
{
    $ids[] = (int) $val;
}
$ids = implode(',', $ids);

$sql3 = mysql_query("INSERT INTO `city_place`(`state_id`,`city_id`,`spaid`) VALUES ('$cityid','$ids',$lid)");

而不是那个city_id我想存储字符串值?

2 个答案:

答案 0 :(得分:0)

您的查询工作正常。 你应该改变" city_id"的数据类型。从int到varchar。

答案 1 :(得分:0)

$lid= mysql_insert_id();

$lid= mysql_insert_id();                  
$cityid = trim(ucwords(strtolower(mysql_real_escape_string($_POST['city']))));

$ids = array();
foreach($_POST['place'] as $key =>$val) // change this line
{
    $ids[] = (int) $key; // change this line
}
$ids = implode(',', $ids);

$sql3 = mysql_query("INSERT INTO `city_place`(`state_id`,`city_id`,`spaid`) VALUES     ('$cityid','$ids',$lid)");