我需要帮助删除在我的文本区域中粘贴值后创建的额外行,
此代码可以正常工作,但如果在我的 textarea 中添加了一个空行,它也会将其上传到我的数据库中,这反过来又搞砸了我的数据库,因为它缺少主键 (ars_no) 条目,所以我无法删除它......我需要在上传到数据库之前删除多余的行,我尝试使用下面的代码无济于事:
function removeEmptyLines($RemedyTicketNo)
{
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $RemedyTicketNo);
}
这是我插入到数据库的代码:
require 'include/DB_Open.php';
if(isset($_POST['DBLoad']))
{
//print_r($_POST);
//die();
$Category2 = $_POST['Category2'];
$Category3 = $_POST['Category3'];
$Status = $_POST['Status'];
$Date = $_POST['Date'];
$Severity = $_POST['Severity'];
$BanType = $_POST['BanType'];
$XiD = $_POST['XiD'];
$Ticket = $_POST['Ticket'];
//Process the input textareas into arrays
$PhoneNumber = array_map('mysql_real_escape_string', explode("\r\n", $_POST['PhoneNumber']));
$Createdate = array_map('mysql_real_escape_string', explode("\r\n", $_POST['Createdate']));
$RemedyTicketNo = array_map('mysql_real_escape_string', explode("\r\n", $_POST['PhoneNumber']));
//Determine the values with the least amoutn 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')";
}
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);
header("Location: smp_backend.php");
}
}