无法使用PHP在MySQL表中插入数据

时间:2016-06-24 12:12:52

标签: php mysql

我正在尝试使用table

将数据从一个PHP插入另一个<?php $sel=mysqli_query($whmcscon, "SELECT * FROM `tbltickets` WHERE `id` = 92376"); $row=mysqli_fetch_array($sel); mysqli_query($formcon, "INSERT INTO `ft_form_17`(`case_number`, `status`, `subject`, `client_group`, `client_name`,`source`) VALUES (".$row[tid].",".$row[status].",".$row[title].",\"GroupA\",\"vaibhav batra\",\"Web\")"); ?>
".$row[tid]."

问题是插入查询仅在我使用$row时才起作用,但如果 dbarray(46) { [0]=> string(5) "92376" ["id"]=> string(5) "92376" [1]=> string(13) "2016062492376" ["tid"]=> string(13) "2016062492376" [2]=> string(1) "1" ["did"]=> string(1) "1" [3]=> string(4) "3565" ["userid"]=> string(4) "3565" [4]=> string(1) "0" ["contactid"]=> string(1) "0" [5]=> string(33) "Vaibhav Batra" ["name"]=> string(33) "Vaibhav Batra" [6]=> string(22) "some@example.com" ["email"]=> string(22) "some@example.com" [7]=> string(0) "" ["cc"]=> string(0) "" [8]=> string(8) "x8MSn3rt" ["c"]=> string(8) "x8MSn3rt" [9]=> string(19) "2016-06-24 00:20:26" ["date"]=> string(19) "2016-06-24 00:20:26" [10]=> string(55) "Unable to send emails" ["title"]=> string(55) "Unable to send emails" [11]=> string(61) "I am not able to send emails" ["message"]=> string(61) "I am not able to send emails" [12]=> string(9) "Follow Up" ["status"]=> string(9) "Follow Up" [13]=> string(6) "Medium" ["urgency"]=> string(6) "Medium" [14]=> string(12) "Nitesh Gupta" ["admin"]=> string(12) "Nitesh Gupta" [15]=> string(0) "" ["attachment"]=> string(0) "" [16]=> string(19) "2016-06-24 08:47:34" ["lastreply"]=> string(19) "2016-06-24 08:47:34" [17]=> string(1) "0" ["flag"]=> string(1) "0" [18]=> string(1) "1" ["clientunread"]=> string(1) "1" [19]=> string(7) "69,76,1" ["adminunread"]=> string(7) "69,76,1" [20]=> string(1) "0" ["replyingadmin"]=> string(1) "0" [21]=> string(19) "0000-00-00 00:00:00" ["replyingtime"]=> string(19) "0000-00-00 00:00:00" [22]=> string(0) "" ["service"]=> string(0) "" } 数组中还有其他变量则会失败。

这是我的Select查询的var_dump

{{1}}

1 个答案:

答案 0 :(得分:1)

您在数组引用和查询本身内都缺少许多单引号。

将您的查询更改为:

mysqli_query($formcon,  "INSERT INTO `ft_form_17`(`case_number`, `status`, `subject`, `client_group`, `client_name`,`source`) VALUES ('".$row['tid']."','".$row['status']."','".$row['title']."','GroupA','vaibhav batra','Web')");