blacklotus90 Posted January 4, 2009 Share Posted January 4, 2009 Hi. I'm trying to make a simple website for a game called assassin. I have a mysql table called players which includes the columns playeralias, playertarget, playerpass, and playerword. Each player has a target that they have to kill and they have to make that target say a certain word to do so. I am trying to make a simple php script that will check a password with one in the database (plaintext, I know it's not secure but I'm just messing around. Same goes for messy code, I'm a beginner), then get the player's target and the word from that target's row. The script works fine in returning the error for an incorrect password or alias, but when I run it in a situation where it should work for returning the player's target etc. the variables do not show up. It simply returns "Your current target is and you must use the word to eliminate them" Is there an obvious error I'm missing? <?php include 'includes/config.php'; include 'includes/opendb.php'; //Define Variables $playeralias = $_POST['alias']; $password = $_POST['password']; //Access SQL data for specified alias $query = "SELECT playerpass FROM players WHERE playeralias = '$playeralias'"; $result = (mysql_query($query)); //Access password and compare it $storedpass = mysql_fetch_row($result); $storedpass = $storedpass[0]; if ($storedpass == $password) { $query = "SELECT * FROM players WHERE playeralias = '$playeralias'"; $result = (mysql_query($query)); $target = mysql_fetch_row($result); $finaltarget = $target['playertarget']; $query = "SELECT * FROM players WHERE playeralias = '$finaltarget'"; $result = (mysql_query($query)); $word = mysql_fetch_row($result); $finalword = $word['playerword']; echo "Your current target is ".$finaltarget." and you must use the word ".$finalword." to eliminate them";} else {exit("<font color=\"white\">Error: Alias or password was incorrect");} include 'includes/closedb.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/139413-problem-fetching-values-from-a-mysql-database-with-php/ Share on other sites More sharing options...
fenway Posted January 4, 2009 Share Posted January 4, 2009 I see lots of queries... what's not working? Quote Link to comment https://forums.phpfreaks.com/topic/139413-problem-fetching-values-from-a-mysql-database-with-php/#findComment-729260 Share on other sites More sharing options...
blacklotus90 Posted January 4, 2009 Author Share Posted January 4, 2009 Neither $finaltarget nor $finalword seem to be getting a value. Quote Link to comment https://forums.phpfreaks.com/topic/139413-problem-fetching-values-from-a-mysql-database-with-php/#findComment-729265 Share on other sites More sharing options...
Gamic Posted January 4, 2009 Share Posted January 4, 2009 is ['playertarget'] the name of the field in the table? <?php $br = "<br />\n"; foreach ($target as $key =>$value){ echo $key.$br; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139413-problem-fetching-values-from-a-mysql-database-with-php/#findComment-729270 Share on other sites More sharing options...
fenway Posted January 4, 2009 Share Posted January 4, 2009 Prove the queries are successful and return results. Quote Link to comment https://forums.phpfreaks.com/topic/139413-problem-fetching-values-from-a-mysql-database-with-php/#findComment-729272 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.