Jump to content

Recommended Posts

I´m getting problems writing to a mysql database from flash using php.

There´re 3 variable to write in: "jugador", "nivel" and "tiempo".

 

The code i´m using to pass variables thorough flash is this:

_root.add_pass = "{changethis}";

_root.name = _root.jugador;

_root.nivel = _root.nivel;

_root.score = _root.tiempo;

getURL("new_score.php", "", "POST");

 

And the php code to write in the database is this (new_score.php):

 

<?

include_once ("_data.php");

$conn = mysql_connect($db_host,$db_user,$db_pass);

mysql_select_db($db_name,$conn);

 

if ($pass==$add_pass) {

 

if ($u_user==1) {

 

$sql3 = "SELECT name FROM $db_table ORDER BY name";

$result3 = mysql_query($sql3);

while($r = mysql_fetch_object($result3))

{

$tmp = "{$r->name}";

if ($name==$tmp) {

$n_exist=1;

 

}

}

if ($n_exist==1) {

$sql1 = "UPDATE $db_table SET score='$score' WHERE name=\"$name\"";

$result1 = mysql_query($sql1);

} else {

$sql1 = "INSERT INTO $db_table (name,score,nivel) VALUES (\"$name\",\"$score\",\"$nivel\")";

$result1 = mysql_query($sql1);

}

 

} else {

$sql1 = "INSERT INTO $db_table (name,score,nivel) VALUES (\"$name\",\"$score\",\"$nivel\")";

$result1 = mysql_query($sql1);

}

 

$sql2 = "SELECT id FROM $db_table ORDER BY score DESC";

$result2 = mysql_query($sql2);

 

$num = 1;

while($r = mysql_fetch_object($result2))

{

$result = mysql_db_query($db_name,"SELECT * from $db_table WHERE id='{$r->id}'");

$resultArray = mysql_fetch_array($result);

$did = $resultArray["id"];

$name = $resultArray["name"];

$score = $resultArray["score"];

$nivel = $resultArray["nivel"];

if ($num>$sec_size) {

$sql3 = "DELETE FROM $db_table WHERE id='$did'";

$result3 = mysql_query($sql3);

}

$num++;

}

}

 

mysql_close ($conn);

?>

 

Something is wrong in the php.

 

TA

Link to comment
https://forums.phpfreaks.com/topic/74307-write-to-mysql-from-flash/
Share on other sites

I need to define all the variables (name, score and nivel) sent via post like this?

 

<?

include_once ("_data.php");

$conn = mysql_connect($db_host,$db_user,$db_pass);

mysql_select_db($db_name,$conn);

 

$name = $_POST['name'];

$score = $_POST['score'];

$nivel = $_POST['nivel'];

 

if ($pass==$add_pass) {

 

if ($u_user==1) {

 

  $sql3 = "SELECT name FROM $db_table ORDER BY name";

  $result3 = mysql_query($sql3);

  while($r = mysql_fetch_object($result3))

  {

      $tmp = "{$r->name}";

      if ($name==$tmp) {

        $n_exist=1;

 

      }

  }

  if ($n_exist==1) {

      $sql1 = "UPDATE $db_table SET score='$score' WHERE name=\"$name\"";

      $result1 = mysql_query($sql1);

  } else {

      $sql1 = "INSERT INTO $db_table (name,score,nivel) VALUES (\"$name\",\"$score\",\"$nivel\")";

      $result1 = mysql_query($sql1);

  }

 

} else {

$sql1 = "INSERT INTO $db_table (name,score,nivel) VALUES (\"$name\",\"$score\",\"$nivel\")";

$result1 = mysql_query($sql1);

}

 

$sql2 = "SELECT id FROM $db_table ORDER BY score DESC";

$result2 = mysql_query($sql2);

 

$num = 1;

while($r = mysql_fetch_object($result2))

{

$result = mysql_db_query($db_name,"SELECT * from $db_table WHERE id='{$r->id}'");

$resultArray = mysql_fetch_array($result);

$did = $resultArray["id"];

$name = $resultArray["name"];

$score = $resultArray["score"];

$nivel = $resultArray["nivel"];

if ($num>$sec_size) {

  $sql3 = "DELETE FROM $db_table WHERE id='$did'";

  $result3 = mysql_query($sql3);

}

$num++;

}

}

 

mysql_close ($conn);

?>

 

 

Or i´m doing wrong??

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.