drsl90685154 2013-05-20 06:17
浏览 24
已采纳

在textarea中处理额外的行

please help...users are pasting values in textarea which results to adding a new line...that new line is being processed and being uploaded to db but does not have values on some columns...how can i eliminate the extra lines prior to processing the textarea and upload to db?

here is my code that process the textarea into arrays:

$PhoneNumber = array_map('mysql_real_escape_string', explode("
", $_POST['PhoneNumber']));
$Createdate = array_map('mysql_real_escape_string', explode("
", $_POST['Createdate']));
$RemedyTicketNo = array_map('mysql_real_escape_string', explode("
", $_POST['PhoneNumber']));

//Determine the values with the least amount of elements

$min_count = min(count($PhoneNumber), count($Createdate), count($RemedyTicketNo));

//Create array to hold INSERT values

$values = array();

//Create the INSERT values

for($index=0; $index<$min_count; $index++)
{
$values[] = "('{$RemedyTicketNo[$index]}','{$PhoneNumber[$index]}','{$Createdate[$index]}',
'$Category2','$Category3','$Status','$Date','$Severity','$BanType','$XiD')";   
}

//inserting to db

if (isset($RemedyTicketNo)) 
{
$sql="INSERT into tbl_main
(ars_no,phone_number,create_date,category_1,category_2,status,resolved_date,trouble_type_priority,ban_type,employee_id_name)
VALUES " . implode (',',$values); 
$result=mysql_query($sql);

im trying to incorporate this code...but its just doesn't seem to work...

$lines = preg_split('/
+/', trim($_POST['textarea']));
$text = implode("
", $lines);

here's how my code looks like when i modify it with the code above:

$PhoneNumber = preg_split('mysql_real_escape_string', '/
+/', trim("
", $_POST['PhoneNumber']));
$Createdate = preg_split('mysql_real_escape_string', '/
+/', trim("
", $_POST['Createdate']));
$RemedyTicketNo = preg_split('mysql_real_escape_string', '/
+/', trim("
", $_POST['PhoneNumber']));


if (isset($RemedyTicketNo)) 
{
$sql="INSERT into tbl_main
    (ars_no,phone_number,create_date,category_1,category_2,status,resolved_date,trouble_type_priority,ban_type,employee_id_name)
VALUES " . implode ('
',$values); 
$result=mysql_query($sql);
  • 写回答

1条回答 默认 最新

  • doumei9832 2013-05-20 07:00
    关注

    this was fixed already...i just re-edited the codes above and only add trim and it worked:

    $PhoneNumber = array_map('mysql_real_escape_string', explode("
    ", trim($_POST['PhoneNumber'])));
    $Createdate = array_map('mysql_real_escape_string', explode("
    ", trim($_POST['Createdate'])));
    $RemedyTicketNo = array_map('mysql_real_escape_string', explode("
    ", trim($_POST['PhoneNumber'])));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了