并非所有$ _Post值都被发送到表。

时间:2013-10-03 20:20:54

标签: php mysql sql arrays post

我使用jotform.com创建了一个表单并且没有调整任何内容只是将action =“”更改为我的.php文件以获取$ _POST查询。我有相同的文件打印$ _POST数组来验证从HTML接收的所有值,所以我不会包含HTML代码。我在下面提交了.php,在表单提交后.php打印出以下数组,确认所有内容都已发布:

successArray ( [formID] => 32750985631157 [q1_referral] => John Doe [q12_contactType] => Array ( [0] => Array ( [0] => Prospect ) ) [q3_companyNameindividual] => John Doe\'s Company [q4_dba] => John Doe\'s D.B.A [q15_mainofficePhone] => Array ( [area] => 305 [phone] => 8654565 ) [q28_mainContact] => Array ( [first] => John [last] => Doe ) [q8_address] => Array ( [addr_line1] => 1223 Cedar Ave [addr_line2] => N/A [city] => Miami [state] => Florida [postal] => 33054 [country] => United States ) [q32_email32] => johndoe@email.com [q11_website11] => johndoe@johndoe.com [q29_secondaryContact] => Array ( [first] => [last] => ) [q10_mainofficePhone10] => Array ( [area] => [phone] => ) [q13_mobilePhone13] => Array ( [area] => [phone] => ) [q14_fax14] => Array ( [area] => [phone] => ) [q20_homePhone20] => Array ( [area] => [phone] => ) [q26_otherPhone] => Array ( [area] => [phone] => ) [q30_email2] => [q31_email3] => [q27_secondaryAddress] => Array ( [addr_line1] => [addr_line2] => [city] => [state] => [postal] => [country] => ) [q23_notes] => [website] => [simple_spc] => 32750985631157-32750985631157 )

mysql表中的所有列都设置为varchar,当然还有除了id之外的255限制。 mysql表中没有显示的值是:

main_contact     varchar(255)           
main_phone   varchar(255)           
main_address     varchar(255)           
Main_address2    varchar(255)           
main_city    varchar(255)           
main_state   varchar(255)           
main_postcode    varchar(255)           
main_country     varchar(255)   

我已经打了好几个小时,确保我正确地编写了php。如果没有人有解决方案,我会发布其他代码。提前谢谢。

<?php
require_once('info.php');

mysqli_query($con,"INSERT INTO contacts(referral,name,dba,main_contact,main_phone,main_address,main_address2,main_city,main_state,main_postcode,main_country,main_email,website_address)VALUES('".$_POST['q1_referral']."','".$_POST['q3_companyNameindividual']."','".$_POST['q4_dba']."','".$_POST['q28_mainContact[first]']."','".$_POST['q15_mainofficePhone[phone]']."','".$_POST['q8_address[addr_line1]']."','".$_POST['q8_address[addr_line2]']."','".$_POST['q8_address[city]']."','".$_POST['q8_address[state]']."','".$_POST['q8_address[postal]']."','".$_POST['q8_address[country]']."','".$_POST['q32_email32']."','".$_POST['q11_website11']."')");

echo "success";
print_r($_POST);
?>

2 个答案:

答案 0 :(得分:1)

您正在错误地使用下标。

例如,您指的是:

$_POST['q28_mainContact[first]']

但实际上你应该看看

$_POST['q28_mainContact']['first']

您的其他字段同样不正确。

答案 1 :(得分:0)

您使用了串联运算符,在此处插入值,即此处

('".$_POST['q1_referral']."','".$_POST['q3_companyNameindividual']."','".$_POST['q4_dba']."','".$_POST['q28_mainContact[first]']."','".$_POST['q15_mainofficePhone[phone]']."','".$_POST['q8_address[addr_line1]']."','".$_POST['q8_address[addr_line2]']."','".$_POST['q8_address[city]']."','".$_POST['q8_address[state]']."','".$_POST['q8_address[postal]']."','".$_POST['q8_address[country]']."','".$_POST['q32_email32']."','".$_POST['q11_website11']."')"

然后删除双引号,使它看起来更像是

('$_POST[q1_referral]','$_POST[q3_companyNameindividual]',
PS:我只是为前两位成员提供了一个想法。