Spring Posted November 6, 2010 Share Posted November 6, 2010 How do I got about outputing one row that can only hold one value? Any reason why the function below doesn't work? <?php include "database.php"; session_start(); $name = $_session['outname']; function output_wins(){ $sql = 'SELECT * FROM account_info WHERE username ="' . $name .'"'; $result = mysql_query($sql); $wins = mysql_fetch_array($result); echo $wins['win']; } output_wins(); ?> Is there an easier way I can output this one row? Quote Link to comment Share on other sites More sharing options...
litebearer Posted November 6, 2010 Share Posted November 6, 2010 Variables do NOT automatically pass to functions. Try... $name = $_session['outname']; function output_wins($name){ $sql = "SELECT * FROM account_info WHERE username = '$name'"; $result = mysql_query($sql); $wins = mysql_fetch_array($result); return $wins['win']; } echo output_wins($name); Quote Link to comment Share on other sites More sharing options...
Spring Posted November 6, 2010 Author Share Posted November 6, 2010 Ehh, it seems to work but it's not outputting anything. It's blank. Quote Link to comment Share on other sites More sharing options...
Spring Posted November 6, 2010 Author Share Posted November 6, 2010 Ah, here's the error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 7, 2010 Share Posted November 7, 2010 change the mysql_query line to this: $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Spring Posted November 7, 2010 Author Share Posted November 7, 2010 change the mysql_query line to this: $result = mysql_query($sql) or die(mysql_error()); I did and this is the error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 7, 2010 Share Posted November 7, 2010 can you post your latest code? Quote Link to comment Share on other sites More sharing options...
Spring Posted November 7, 2010 Author Share Posted November 7, 2010 <?php include "database.php"; session_start(); $name = $_session['outname']; function output_wins($name){ $sql = "SELECT * FROM account_info WHERE username = '$name'"; $result = mysql_query($sql) or die(mysql_error()); $wins = mysql_fetch_array($result); return $wins['win']; } ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 7, 2010 Share Posted November 7, 2010 mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 8, correct? I guess we need to look at the sql. try this or something similar: function output_wins($name){ $sql = "SELECT * FROM account_info WHERE username = '$name'"; echo "sql: $sql <br />"; $result = mysql_query($sql) or die(mysql_error()); echo "result: ".$result."<br />"; $wins = mysql_fetch_array($result); echo "after mysql_fetch_array <br />"; return $wins['win']; } Quote Link to comment Share on other sites More sharing options...
Spring Posted November 7, 2010 Author Share Posted November 7, 2010 Edit: got this: sql: SELECT * FROM account_info WHERE username = "tony" result: Resource id #3 after mysql_fetch_array 0 Quote Link to comment Share on other sites More sharing options...
Spring Posted November 7, 2010 Author Share Posted November 7, 2010 Everything is working great now! I figured out what happen! Thanks! Quote Link to comment 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.