Query Help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
HaVoC
Forum Commoner
Posts: 83
Joined: Sat Feb 07, 2004 7:20 am
Location: Smiths Falls, CA

Query Help

Post by HaVoC »

Code: Select all

<?php
$id = $_GET['id']; 
$winner = $_GET['winner']; 
$loser = $_GET['loser']; 
$observer = $_GET['observer']; 

MySQL_query("UPDATE ldu_users SET wins = wins - 1, points = points - 2 WHERE user_name = {$winner}");
MySQL_query("UPDATE ldu_users SET losses = losses - 1, points = points + 1 WHERE user_name = {$loser}");
MySQL_query("UPDATE ldu_users SET obs = obs - 1 WHERE user_name = {$observer}");
?>
Ok I used the get ID in another query. And it always works. What is wrong with the queries you see? It has to do with the queries.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Imagine my name is Foo Bar, and what that does to a query:

Code: Select all

MySQL_query("UPDATE ldu_users SET wins = wins - 1, points = points - 2 WHERE user_name = Foo Bar");
Can you see what the issue will be?

Try adding singe quotes around values:

Code: Select all

MySQL_query("UPDATE ldu_users SET wins = wins - 1, points = points - 2 WHERE user_name = '&#123;$winner&#125;'");
User avatar
HaVoC
Forum Commoner
Posts: 83
Joined: Sat Feb 07, 2004 7:20 am
Location: Smiths Falls, CA

Post by HaVoC »

Well I thought of doing that, but in phpMyAdmin the query told me to use " " and when I did it worked. But when I did it outside of phpMyAdmin I got a parse error :(
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Adding " " (double quotes) within the lines you posted first, would break them for sure with parsing errors.

There is a difference between single ' and double " quotes, and I'm just trying to make sure you use it correctly. No matter how good we all think phpMyAdmin is, there are issues with it's query-tool if used incorrectly.

" In phpMyAdmin, might aswell be ' in php outside phpMyadmin.
User avatar
HaVoC
Forum Commoner
Posts: 83
Joined: Sat Feb 07, 2004 7:20 am
Location: Smiths Falls, CA

Post by HaVoC »

Thanks ^^
Post Reply