/    Sign up×
Community /Pin to ProfileBookmark

php mysql help

How can i make this work?

in the top of my php file i have

[code=php]$stuff = $_GET[‘p’];
$stuff = end(explode(‘=’, $_SERVER[‘REQUEST_URI’]));[/code]

further down i have

[code=php]$sql = ‘SELECT * FROM `quotes` where game = ‘$stuff’ LIMIT 0, 30 ‘;[/code]

Fatal error: Database::_sql(); -> Query error:

why wont this work? :/

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@skywalker2208Aug 14.2010 — Is that the exact database error?

Also, what is stored in the $stuff variable?

Plus I also don't understand why you set the $stuff variable on the first line then on the next line you overwrite it.
Copy linkTweet thisAlerts:
@evaniaauthorAug 14.2010 — ah sorry, in $stuff everyting after the "=" in this url is stored http://mypage.net/index.php?p=twarp so for that url "twarp" would be in $stuff

and yes that's the exact error im getting
Copy linkTweet thisAlerts:
@NogDogAug 14.2010 — You have the query string in single quotes, and therefore $stuff will not be evaluated as a PHP variable.
[code=php]
$sql = "SELECT * FROM quotes where game = '$stuff' LIMIT 0, 30";
[/code]
Copy linkTweet thisAlerts:
@evaniaauthorAug 14.2010 — You have the query string in single quotes, and therefore $stuff will not be evaluated as a PHP variable.
[code=php]
$sql = "SELECT * FROM quotes where game = '$stuff' LIMIT 0, 30";
[/code]
[/QUOTE]


thank you, however i noticed this was just 1 part of my problem

this is my code

[code=php]
$stuff = $_GET['p'];
$stuff = end(explode('=', $_SERVER['REQUEST_URI']));
case '$stuff':
$sql = "SELECT * FROM quotes where game = '$stuff' LIMIT 0, 30";
$r = $db->_sql($sql);
while ($row = $db->fetch_row($r)) {
$tpl->set('q_id', $row['id']);
$tpl->set('q_rating', $row['rating']);
$tpl->set('quote', $row['quote']);
$sql = "SELECT ip FROM ".$_qdbs[tpfx]."votes WHERE id='".mysql_real_escape_string($row['id'])."' AND ip='".mysql_real_escape_string($ip)."'";
$r2 = $db->_sql($sql);
$row2 = $db->fetch_row($r2);
if ($row2['ip'] != $ip) {
$rate = $tpl->fetch($tpl->tdir.'quote_rate.tpl');
$tpl->set('q_rate', $rate);
} else {
$tpl->set('q_rate', '');
}
print($tpl->fetch($tpl->tdir.'game.tpl'));
}[/code]


the "case '$stuff':" at the top wont work either :/ the case part is so that if my url is http://mypage.net/index.php?p=twarp the code under "case 'someting':" only runt if it matches whats after the = and currently having $stuff wont work, do you know why? :/
Copy linkTweet thisAlerts:
@skywalker2208Aug 14.2010 — First off you are overwritten the first $stuff with the second line
[code=php]$stuff = $_GET['p'];
$stuff = end(explode('=', $_SERVER['REQUEST_URI'])); [/code]


If this is your whole code then you are missing the start of the switch statement, plus you have $stuff in single quotes for your case statement, which isn't correct because it evaluates $stuff as $stuff and not what is contained in stuff.

[code=php]
case '$stuff':
//should be
case $stuff:
[/code]
×

Success!

Help @evania spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 9.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @ddiebold17,
tipped: article
amount: 1000 SATS,

tipper: @Mqlinka19,
tipped: live stream
amount: 4900 SATS,

tipper: @Mqlinka19,
tipped: article
amount: 10 SATS,
)...