This topic has been of great help to me, as this is my first project with MySQL. Unfortunately, there's still something wrong with my code which is preventing it from working.
I have a simple one table MySQL database with 4 fields: numero, nome, email, resultado. Sorry about the Portuguese but I think its preferable, for the sake of better understanding my code, which follows:
Code: Select all
$nome = $_POST["nomeVar"];
//$nome = "rf teste";
$email = '';
$results = mysql_query("SELECT email FROM colaboradores WHERE nome = '$nome'")or die(mysql_error());
while($row = mysql_fetch_assoc($results)) {
if($email != '') { $email .= ', '; }
$email .= $row['email'];
}
mysql_free_result($result);
mysql_close($link);
if($email != '') { $email .= ''; }
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
echo "<colaboradores>\n";
echo "<email>" . $email . "</email>\n";
echo "</colaboradores>\n";
$sendTo = "ricardo.ferreira@pointoview.net";
$headers = "From: " . $nome;
$subject = "qemail.php - Resultado de " . $email;
$message = "O nosso colaborador, " . $nome . ";
mail($sendTo, $subject, $message, $headers);
I have a flash quizz game which populates a combobox with the names from the database (through PHP and XML). After answering the questions, each user selects his name and, by pressing a confirmation button, the DB should be queried for the corresponding e-mail address and then return it to flash. The result is also inserted in the DB (no problem with that).
I just can't understand what's wrong with this. If I assign the "nome" in the PHP, using the commented 2nd line of code, the query is executed and I get the intended e-mail address back, in XML, ready to be read by flash.
When I send the variable from flash, it reaches PHP and is sent back to me via e-mail but, it fails to reach MySQL as the query isn't executed. Consequently, I get a null result in my flash application.
Somehow, the variable "nomeVar" sent from flash to php is lost between querying for the corresponding e-mail address and sending the "email" variable back to flash.
I hope I've clearly put it down for you. Thanks in advance
Regards
RF