tiken Posted October 22, 2007 Share Posted October 22, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/74307-write-to-mysql-from-flash/ Share on other sites More sharing options...
trq Posted October 22, 2007 Share Posted October 22, 2007 I don't see anywhere in the php script where you define these variables. Take a look in the $_POST array. Quote Link to comment https://forums.phpfreaks.com/topic/74307-write-to-mysql-from-flash/#findComment-375427 Share on other sites More sharing options...
tiken Posted October 22, 2007 Author Share Posted October 22, 2007 Did i really need to define the variables in php?? This script only captures the flash variables and writes this on the specified database tables... Quote Link to comment https://forums.phpfreaks.com/topic/74307-write-to-mysql-from-flash/#findComment-375436 Share on other sites More sharing options...
GingerRobot Posted October 22, 2007 Share Posted October 22, 2007 If the variables are being sent with the POST method, you'll need to get the variables from the $_POST array, unless you have register_globals turned on. For example: <?php $name = $_POST['name']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74307-write-to-mysql-from-flash/#findComment-375438 Share on other sites More sharing options...
tiken Posted October 22, 2007 Author Share Posted October 22, 2007 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?? Quote Link to comment https://forums.phpfreaks.com/topic/74307-write-to-mysql-from-flash/#findComment-375444 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.