Jump to content

database method


hasek522

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.