hasek522 Posted July 25, 2008 Share Posted July 25, 2008 I beleive I have a problem with how im creating a select statement in PHP that is causing an error with a method: Heres the error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/brandoo8/public_html/jasonhedrick/mymoney/viewaccount.php on line 15 Heres the code: $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); $accountid = $_GET['accountid']; $id = $_SESSION['USERID']; $sql = "SELECT * FROM accounts WHERE userid = '" . $id . "', id = '" . $accountid . "';"; $query = mysql_query($sql); if(mysql_num_rows($query) >= 1) { while($row = mysql_fetch_array($query)) { $name = $row['name']; $expenses= '$' . number_format($row['expenses'],2); $profits= '$'. number_format($row['profits'],2); $balance= '$'. number_format($row['balance'],2); } } else { echo 'INVALID VIEW ACCOUNT <br />'; } Link to comment https://forums.phpfreaks.com/topic/116631-database-method/ Share on other sites More sharing options...
MFHJoe Posted July 25, 2008 Share Posted July 25, 2008 Don't quote me on this, but I think you can't separate WHERE clauses with a comma. I think it needs to be AND. Try this: $sql = "SELECT * FROM accounts WHERE userid = '" . $id . "' AND id = '" . $accountid . "'"; Link to comment https://forums.phpfreaks.com/topic/116631-database-method/#findComment-599681 Share on other sites More sharing options...
craygo Posted July 25, 2008 Share Posted July 25, 2008 if you use some error checking you will see your problem $query = mysql_query($sql)or die(mysql_error()); once you see the error code you would find out that WHERE clauses are seperated by AND not a comma as well as you added an extra semi colon WHERE userid = '" . $id . "' AND id = '" . $accountid . "'"; Ray Link to comment https://forums.phpfreaks.com/topic/116631-database-method/#findComment-599682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.