这是我希望我的 SQL 语句将数据插入到数据库的方式:
INSERT into tbl_main (ars_no, phone_number, category_1, category_2, status, create_date, resolved_date, trouble_type_priority, ban_type, employee_id_name)
和的值将来自我的文本区域ars_no
...然后这些文本区域中的每一行将对应于我的文本字段的固定值,即, , , , , ,phone_number
create_date
category_1
category_2
status
resolved_date
trouble_type_priority
ban_type
employee_id_name
因此,当插入到我的 sql 中时,我的 textareas 中的每一行都是一个新行,并且将创建的所有行都将具有来自我的文本字段的添加的固定值...
但每次我尝试插入数据...它给我一个消息它是成功的但是当我检查数据库时没有数据,下面是我的 sql 代码,请告知我的代码是否正确或者是否可以做得更好,
error_reporting(E_ALL);
require 'include/DB_Open.php';
if(isset($_POST['DBLoad']))
{
$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("\n", $_POST['PhoneNumber']));
$Createdate = array_map('mysql_real_escape_string', explode("\n", $_POST['Createdate']));
$RemedyTicketNo = array_map('mysql_real_escape_string', explode("\n", $_POST['PhoneNumber']));
//Determine the values with the least amount of elements
$min_count = min($PhoneNumber, $Createdate, $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')";
}
$sql=mysql_query("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));
if (!$sql) {
die('Invalid query: ' . mysql_error());
}
header("Location: smp_backend_test.php");
}
我想我在这里发现了错误,我已经回应了我的 INSERT 语句,它只是这样做:
INSERT into tbl_main (ars_no, phone_number, category_1, category_2, status, create_date, resolved_date, trouble_type_priority, ban_type, employee_id_name) VALUES ('('1', '1', '1'), ('2', '2', '2')', 'SMP_Backend', 'Pending Request', 'Resolved', '2013-04-28', '5', 'I', 'AAA')
我想要它做的是我的 textarea 中的每一行都将与我的 textfields 值相关联,有没有办法编辑我的 INSERT 语句以便它在下面执行,它应该这样做:
INSERT into tbl_main (ars_no, phone_number, category_1, category_2, status, create_date, resolved_date, trouble_type_priority, ban_type, employee_id_name)
VALUES ('('1', '1', '1', 'SMP_Backend', 'Pending Request', 'Resolved', '2013-04-28', '5', 'I', 'AAA'), ('2', '2', '2', 'SMP_Backend', 'Pending Request', 'Resolved', '2013-04-28', '5', 'I', 'AAA')')