我有一些从adobe flash AS3收到的数据,PHP文件收到它,但我似乎无法将数据发送到mySQL ...
这是我的PHP代码:
<?php
if(isset($_POST['userFirstName'])){ $userFirstName = $_POST['userFirstName']; }
if(isset($_POST['userLastName'])){ $userLastName = $_POST['userLastName']; }
if(isset($_POST['userEmail'])){ $userEmail = $_POST['userEmail']; }
if(isset($_POST['userNumber'])){ $userNumber = $_POST['userNumber']; }
if(isset($_POST['userMsg'])){ $userMsg = $_POST['userMsg']; }
$username="******";
$password="*******";
$database="b-elite-fitness";
mysql_connect("localhost","$username","$password") or die (mysql_error());
mysql_select_db("$database") or die (mysql_error());
mysql_query("INSERT INTO formdp
(ID ,firstname, lastname, email, number, message)
VALUES('','$userFirstName[firstname]','$userLastName[lastname]','$userEmail[email]','$userNumber[number]','$userMsg[message]')")
or die (mysql_error());
echo "foo=bar&checking=ok";
mysql_close();
?>
我收到了php文件的错误...
( ! ) Notice: Undefined variable: userFirstName in C:\wamp\www\NewtestForm\form.php on line 18 Call Stack
# Time Memory Function Location 1
0.0094 253176 {main}( ) ..\form.php:0
( ! ) Notice: Undefined variable: userLastName in C:\wamp\www\NewtestForm\form.php on line 18 Call Stack
# Time Memory Function Location 1
0.0094 253176 {main}( ) ..\form.php:0
( ! ) Notice: Undefined variable: userEmail in C:\wamp\www\NewtestForm\form.php on line 18 Call Stack
# Time Memory Function Location 1
0.0094 253176 {main}( ) ..\form.php:0
( ! ) Notice: Undefined variable: userNumber in C:\wamp\www\NewtestForm\form.php on line 18 Call Stack
# Time Memory Function Location 1
0.0094 253176 {main}( ) ..\form.php:0
( ! ) Notice: Undefined variable: userMsg in C:\wamp\www\NewtestForm\form.php on line 18 Call Stack
# Time Memory Function Location 1
0.0094 253176 {main}( ) ..\form.php:0
任何人都可以帮助我,过去几天我一直在解决这个问题......
我是PHP的新手,所以也可以解释......
编辑更新....我改变了编码,但仍然得到相同的错误......这是我的新编码......
<?php
if(isset($_POST['userFirstName'])){ $userFirstName = $_POST['userFirstName']; }
if(isset($_POST['userLastName'])){ $userLastName = $_POST['userLastName']; }
if(isset($_POST['userEmail'])){ $userEmail = $_POST['userEmail']; }
if(isset($_POST['userNumber'])){ $userNumber = $_POST['userNumber']; }
if(isset($_POST['userMsg'])){ $userMsg = $_POST['userMsg']; }
$username="root";
$password="dp10aap";
$database="b-elite-fitness";
mysql_connect("localhost","$username","$password") or die (mysql_error());
mysql_select_db("$database") or die (mysql_error());
mysql_query("INSERT INTO formdp
(id ,firstname, lastname, email, number, message)
VALUES('NULL','$userFirstName','$userLastName','$userEmail','$userNumber','$userMsg')")
or die (mysql_error());
mysql_close();
?>
这是我的错误......
(!)注意:未定义的变量:第18行的C:\ wamp \ www \ NewtestForm \ form.php中的userFirstName 调用堆栈
1 0.0112 252456 {main}().. \ form.php:0
(!)注意:未定义的变量:第18行的C:\ wamp \ www \ NewtestForm \ form.php中的userLastName 调用堆栈
1 0.0112 252456 {main}().. \ form.php:0
(!)注意:未定义的变量:第18行的C:\ wamp \ www \ NewtestForm \ form.php中的userEmail 调用堆栈
1 0.0112 252456 {main}().. \ form.php:0
(!)注意:未定义的变量:第18行的C:\ wamp \ www \ NewtestForm \ form.php中的userNumber 调用堆栈
1 0.0112 252456 {main}().. \ form.php:0
(!)注意:未定义的变量:第18行的C:\ wamp \ www \ NewtestForm \ form.php中的userMsg 调用堆栈
1 0.0112 252456 {main}().. \ form.php:0
答案 0 :(得分:1)
这是不正确的:$userFirstName[firstname]
我假设$_POST['userFirstName']
是一个字符串,在这种情况下,您只能使用$userFirstName
来访问该变量。如果是数组,则缺少引号来访问数组索引:$userFirstName['firstname']
。
其他变量也是如此。
答案 1 :(得分:0)
您通过向其添加['identifier']
来创建自己的变量关联数组。这使得它们与最初的不同,然后你尝试使用它们,就好像你已经在它们中加入了一些值,这就是你得到错误的原因。只要按原样使用它们。喜欢这个
mysql_query("INSERT INTO formdp (ID ,firstname, lastname, email, number, message)
VALUES('','$userFirstName','$userLastName','$userEmail','$userNumber','$userMsg')")
or die (mysql_error());
请记住清理用户的输入,并注意不推荐使用PHP
的{{1}}扩展名。考虑mysql
或mysqli
。
答案 2 :(得分:0)
您的PHP代码未收到您的POSt数据。你有没有在$ _POSt上做一个var_dump来看看它究竟持有什么?