I searched daniweb, google, etc. All had multible code snippets but I couldnt get any to work..

Well my database is "wallet" and in the row is "id" and "amount"

So I tried like

$result = mysql_query("SELECT amount FROM wallet WHERE id LIKE '%$id%'");

while ($row = mysql_fetch_assoc($result)) {
	$money = stripslashes($row["amount"]);
}

But that just gives me

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

..Anybody help? its been busting my brain for days now.

Am sure this is not all code. The error you get means the query has failed. Post more code.

The other bits of the code are in a seperate PHP file, Its used to connect.

Its used with 3 other codes and they work perfectly, So im pretty sure its not the connection, But okay

GET.PHP
<?php
include ('db.php');

$id = $_GET["id"];

$connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>');
mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>');

$result = mysql_query("SELECT amount FROM wallet WHERE id LIKE '%$id%'");

while ($row = mysql_fetch_assoc($result)) {
	$money = stripslashes($row["amount"]);
}
?>
DB.PHP
<?php
	$host = 'localhost';
	$username = 'nopeaky.';
	$password = 'nopeaky.';
	$database = 'nopeaky.';
?>

I tried that kind of thing

$SQL = "SELECT * FROM friends";

I can get the values outta it but it only seems to use the first one or the last one and none of the others

Im trying to compare $id to id, And if it matches then set $money to the rows 'amount'

Try:

$id = (int) $_GET['id'];
...
$result = mysql_query("SELECT amount FROM wallet WHERE id = '$id'");

Why do you use a while loop, and overwrite $money each time ?

Anyway:

$result = mysql_query("SELECT amount FROM wallet WHERE id LIKE '%$id%'") or die(mysql_error());

will tell you if the query fails. Is id perhaps an integer field ?

@momo219 is correct. Don't use LIKE when comparing for a number. LIKE works with strings and the '%' is a wildcard that matches ANY CHARACTER(S).

Why do you use a while loop, and overwrite $money each time ?

Anyway:

$result = mysql_query("SELECT amount FROM wallet WHERE id LIKE '%$id%'") or die(mysql_error());

will tell you if the query fails. Is id perhaps an integer field ?

Actually I just did that, And the error dumped "Table 'nopeaky.wallet/' doesn't exist"

Why is it adding that /...?

MySQL Is telling you that the table doesn't exist.
Are you sure you've got the right table names?
Also, try using these (`) around table and field names.

$result = mysql_query("SELECT `amount` FROM `wallet` WHERE `id` LIKE '%$id%'") or die(mysql_error());

adding the '' worked

Thanks guys, I owe you guys one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.