Flash UI->ActionScript->PHP->MySQL->INSERT INTO

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Flash UI->ActionScript->PHP->MySQL->INSERT INTO

Postby NewToPHP » 23. May 2004 19:51

Hello All, I am having a problem integrating Flash, PHP and MySQL. See below:

I get the values from the user in a Flash Form User Interface
Flash passes the values to the php using actionscripting
the php file uses the HTTP GET method to get the values from the actionscript
the php file then checks to make sure the values are not null (additional check even though this is done on the client side)
the php file then converts all the values to uppercase to eliminate case sensitivity
the php file then strips out any foreign characters (not quite sure how I'm going to get urls from the user yet...http://www.userwebsite.com)
the php file then opens a connection to the MySQL database using the database function mysql_connect (if a connection could not be established, the php exits via a die() function)
the php file then inserts the data into the database using the INSERT INTO sql command with the following syntax:
$query = "INSERT INTO feedback_table (FeedbackFName, FeedbackLName, FeedbackEmail, FeedbackText)
VALUES ('$FeedbackFName', '$FeedbackLName', '$FeedbackEmail', '$FeedbackText')";
$result = mysql_query($query);


the php file then checks to make sure the data was inserted using the following code:
$numR = mysql_num_rows($result);

// If the number of rows is not equal to one then it prints out an error statement
if ($numR == 1) {
print "Status=Success";
}
else {
print "Status=Failure";
}
}


This is where it all falls apart. The data never shows up in the database and I am unable to see any MySQL error messages when I use echo mysql_error(), or mysql_errno()

I am using an WindowsXP machine
I have successfully installed XAMPP for windows
I see the mysqld process in my task manager

I don't know what I am doing wrong. Here is the code below...any assistance would be greatly appreciated!! Thanks!

/******************************************************************************************************************************************/
/* get the data sent by the flash application */
$FeedbackFName = $_GET['FeedbackFName'];
$FeedbackLName = $_GET['FeedbackLName'];
$FeedbackEmail = $_GET['FeedbackEmail'];
$FeedbackText = $_GET['FeedbackText'];

/* check form values */
if(empty($FeedbackFName)|| empty($FeedbackLName)|| empty($FeedbackEmail)|| empty($FeedbackText))
{
print "UNABLE TO RETRIEVE VALUES FROM FLASH APPLICATION";
die();
}
else{

/* This line of Code changes the name to all UPPERCASE. This is so that the input is not case sensitive. You can make it case sensitive by leaving this line out.*/
$FeedbackFName = strtoupper ($FeedbackFName);
$FeedbackLName = strtoupper ($FeedbackLName);
$FeedbackEmail = strtoupper ($FeedbackEmail);
$FeedbackText = strtoupper ($FeedbackText);


/* This line takes out everything that is not a captital or lowercase letter or a interger between 0 and 9. This line is only for security purposes so that users can not enter anything that could disrupt the database. You can take this line out if you want. Or you can allow users to enter other symbols by including a \ followed by that character right after.*/
$FeedbackFName = ereg_replace("[^A-Za-z0-9 ]", "", $FeedbackFName);
$FeedbackLName = ereg_replace("[^A-Za-z0-9 ]", "", $FeedbackLName);
$FeedbackEmail = ereg_replace("[^A-Za-z0-9 ]", "", $FeedbackEmail);
$FeedbackText = ereg_replace("[^A-Za-z0-9 ]", "", $FeedbackText);

// Connects to the database.
if(!mysql_connect($DBhost,$DBuser,$DBpass))
{
print "UNABLE TO CONNECT TO THE DATABASE!!";
echo mysql_errno().": ".mysql_error()."<BR>";
print mysql_errno().": ".mysql_error()."<BR>";
die();
}
mysql_select_db("$DBName");
echo mysql_errno().": ".mysql_error()."<BR>";
print mysql_errno().": ".mysql_error()."<BR>";

print "DATABASE CONNECTION DETECTED SENDING >> ";
echo $QUERY_STRING;
print "TO THE DATABASE USING THE!";
echo $REQUEST_METHOD;
print "METHOD";

//will be sent to the database:

echo $FeedbackFName;
echo $FeedbackLName;
echo $FeedbackEmail;
echo $FeedbackText;
// Use the following query to insert user's data into the database
$query = "INSERT INTO feedback_table (FeedbackFName, FeedbackLName, FeedbackEmail, FeedbackText)
VALUES ('$FeedbackFName', '$FeedbackLName', '$FeedbackEmail', '$FeedbackText')";

//mysql_query = actual database execution statement. Get the result of the execution...success or failure
$result = mysql_query($query);


/* This just gets the number of rows affected with the above Query which should be 1. If exactly 1 row wasn't affected, an error is sent back to the flash app */
$numR = mysql_num_rows($result);

// If the number of rows is not equal to one then it prints out an error statement
if ($numR == 1) {
print "Status=Success";
}
else {
print "Status=Failure";
}
}
?>
:cry:
NewToPHP
 
Posts: 1
Joined: 19. May 2004 01:13
Location: United States

Postby Wiedmann » 23. May 2004 20:35

With this query:
Code: Select all
$query = "INSERT INTO feedback_table (FeedbackFName, FeedbackLName, FeedbackEmail, FeedbackText)
VALUES ('$FeedbackFName', '$FeedbackLName', '$FeedbackEmail', '$FeedbackText')";
$result = mysql_query($query);

$result can only have the value TRUE or FALSE

For the function mysql_num_rows($result), $result must be a resource id.

Have you checked with phpMyadmin the content of your database after the execution of the script?

Look in your phperror.log (/xampp/apache/logs).

for:
Code: Select all
if(!mysql_connect($DBhost,$DBuser,$DBpass))
{
print "UNABLE TO CONNECT TO THE DATABASE!!";
echo mysql_errno().": ".mysql_error()."<BR>";
print mysql_errno().": ".mysql_error()."<BR>";
die();
}

better:
Code: Select all
$link = mysql_connect($DBhost, $DBuser, $DBpass)
   or die ('UNABLE TO CONNECT TO THE SERVER!!:<br />'.mysql_error());



for:
Code: Select all
mysql_select_db("$DBName");
echo mysql_errno().": ".mysql_error()."<BR>";
print mysql_errno().": ".mysql_error()."<BR>";

better:
Code: Select all
mysql_select_db($DBName, $link)
   or die ('UNABLE TO USE THE DATABASE!!:<br />'.mysql_error());



for:
Code: Select all
$query = "INSERT INTO feedback_table (FeedbackFName, FeedbackLName, FeedbackEmail, FeedbackText)
VALUES ('$FeedbackFName', '$FeedbackLName', '$FeedbackEmail', '$FeedbackText')";
$result = mysql_query($query);
$numR = mysql_num_rows($result);
if ($numR == 1) {
print "Status=Success";
}
else {
print "Status=Failure";
}

better:
Code: Select all
$query = "INSERT INTO feedback_table (FeedbackFName, FeedbackLName, FeedbackEmail, FeedbackText)
    VALUES ('$FeedbackFName', '$FeedbackLName', '$FeedbackEmail', '$FeedbackText')";
$result = mysql_query($query)
   or die ('WRONG QUERY!!:<br />'.mysql_error());
echo 'Status=Success';


I think that's enough for the moment (hope that works) ;-)
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby MAGnUm » 28. May 2004 00:22

first make sure the flash script is passing the variables, echo $var_name if that is working try your query in phpmyadmin with some junk data just to see if it really is inserting, then place that junk query in your php file where you set up the db connection and see if it again passes the data, once that is done put it together. if you break it down into simpler pieces you can then recombine, and figure out what is wrong.
~~:M A G n U m:~~
(Disclaimer: if any of this info is confusing or vague tough, its free!!)
User avatar
MAGnUm
 
Posts: 151
Joined: 16. October 2003 18:08
Location: USA


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 58 guests