0

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.

5
Contributors
10
Replies
11
Views
5 Years
Discussion Span
Last Post by Netsurfers
0

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.';
?>
0

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'

0

Try:

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

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 ?

0

@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).

0

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 /...?

0

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());
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.