0

I have some data which is received from adobe flash AS3, the PHP file receives it, but I cant seem to send the data to mySQL...

Here is my PHP code:

<?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();
?>

I get this error for the php file...

( ! ) 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

Can anyone help me out I've been going at the problem for the past few days...

I'm new to PHP so could do with explanations as well...

EDIT UPDATE.... I changed the coding, however still get the same errors... here is my new coding....

<?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();
?>

and here are my errors...

( ! ) Notice: Undefined variable: userFirstName in C:\wamp\www\NewtestForm\form.php on line 18 Call Stack

Time Memory Function Location

1 0.0112 252456 {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.0112 252456 {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.0112 252456 {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.0112 252456 {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.0112 252456 {main}( ) ..\form.php:0

4
  • If these variables are undefined, your initial isset calls are returning false, so in fact your PHP is not receiving the data you are POSTing. The problem is elsewhere. Commented Mar 10, 2013 at 21:01
  • 1
    fyi mysql is deprecated, and this code is vulnerable to SQL injection. you should be using placeholders with mysqli or PDO Commented Mar 10, 2013 at 21:03
  • use NULL instead of '' for your ID field. Presuming you have set the ID field to an auto incrementing integer? Commented Mar 10, 2013 at 21:09
  • @fuzic Could you help me identify where the problem may lay... if i show you my AS3 coding as well... as i initily thought that the error was between AS3 and PHP and not PHP to MYSQL...? Commented Mar 10, 2013 at 21:40

3 Answers 3

1

This is incorrect: $userFirstName[firstname]

I assume that $_POST['userFirstName'] is a string, in which case you would only use $userFirstName to access the variable. If it is an array, you are missing quotes to access the array index: $userFirstName['firstname'].

The same goes for the rest of your variables.

Sign up to request clarification or add additional context in comments.

1 Comment

I get the following error now.... Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING
0

You made your own variables associative arrays by adding ['identifier'] to them. That makes them different from the initial ones, and then you try to use them as if you have put some value in them, that's why you get the errors. Just use them the way they are. Like this

mysql_query("INSERT INTO formdp (ID ,firstname, lastname, email, number, message) 
VALUES('','$userFirstName','$userLastName','$userEmail','$userNumber','$userMsg')")
or die (mysql_error());

Remember to sanitize your user's input and also note that PHP's mysql extenstion is deprecated. Consider mysqli or PDO.

5 Comments

I changed it like you suggested, i get a final error of Parse error: syntax error, unexpected end of file... on the last line
I still get the same errors... after checking my coding i missed out " i added it and get the same error as i did before even after changing the coding as you suggested... @chibuzo
@user2080616 edit your question and add the code for your form, let's start from there.
there you go I've changed the coding as you suggested, however i get the same errors... any ides ?
Your $_POST variables are most likely not set.
0

Your php code is not receiving your POSt data. Have you done a vardump on $_POSt to see what exactly it is holding?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.