...

View Full Version : PHP/MySQL If Trouble



the-dream
01-01-2008, 06:44 PM
Ok i need help with this:



<?php require_once('../Connections/SpotXbox_NEW_DB.php'); ?>
<?php
$colname_rsFindInfo = "-1";
$colname_rsFindInfo = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
mysql_select_db($database_SpotXbox_NEW_DB, $SpotXbox_NEW_DB);
if(isset($_GET['game'])) {
$query_rsFindInfo = sprintf("SELECT * FROM games WHERE name = %s", $colname_rsFindInfo);
} else {
$query_rsFindInfo = sprintf("SELECT * FROM games WHERE id = %s", $colname_rsFindInfo);
}
$rsFindInfo = mysql_query($query_rsFindInfo, $SpotXbox_NEW_DB) or die(mysql_error());
$row_rsFindInfo = mysql_fetch_assoc($rsFindInfo);
$totalRows_rsFindInfo = mysql_num_rows($rsFindInfo);
?>

The bit i am having trouble with is the ( if ) statement! If the "game" is set it wont execute the query! But if the "if" is set it will! Anything I'm doing wrong, anything you can spot please tell me!!

Thanks,
~ Christian

followinto
01-01-2008, 07:14 PM
Make sure your $_GET['game'] is actualy being set first (test it by echoing the var)
Second make sure the previous coding is being executed

tonyyeb
01-01-2008, 07:16 PM
Best to assign the form field to a php variable first. Check this example I have done to see how isset doesn't work for you as isset checks whether a variable has been assigned:



<?php

$var = $_GET['game'];

if ($var <> "") {
echo "Var is set!";
}else{
echo "Var is not set";}

echo "<br>";

if(isset($var)) {
echo "Var is set!";
}else{
echo "Var is not set";}

?>

<br>

<FORM METHOD="GET" action="test.php">
<input type="text" name="game" size="10" maxlength="15" />
<input type="submit" value="Create Tournament" />
</form>


See example 1 here as well for more detail: http://uk3.php.net/isset

Hope this helps

the-dream
01-01-2008, 07:17 PM
Would it matter if there were spaces ( %20 ) in my get eg game.php?game=Assassins%20Creed ????

the-dream
01-01-2008, 07:20 PM
Oh, The isset() is working it just doesn't execute the MySQL when the GET is game but it does when the GET is id!!!

the-dream
01-01-2008, 07:30 PM
Really sorry guys and Thanks for all your help!

I fixed it, i took away the sprint's and assigned the GET's to vars and put them in the query with ' ' round them. Look!


<?php require_once('../Connections/SpotXbox_NEW_DB.php'); ?>
<?php
$colname_rsFindInfo = "-1";
$colname_rsFindInfo = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
mysql_select_db($database_SpotXbox_NEW_DB, $SpotXbox_NEW_DB);

$game = $_GET['game'];
$id = $_GET['id'];

if(isset($_GET['game'])) {
$query_rsFindInfo = "SELECT * FROM games WHERE name = '$game'";
} else {
$query_rsFindInfo = "SELECT * FROM games WHERE id = '$id'";
}
$rsFindInfo = mysql_query($query_rsFindInfo, $SpotXbox_NEW_DB) or die(mysql_error());
$row_rsFindInfo = mysql_fetch_assoc($rsFindInfo);
$totalRows_rsFindInfo = mysql_num_rows($rsFindInfo);
?>

tonyyeb
01-01-2008, 07:31 PM
Oh, The isset() is working it just doesn't execute the MySQL when the GET is game but it does when the GET is id!!!

Oh dear! I often find I get my own solutions after I have posted it on a forum or got someone else to look at it! Glad it is sorted.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum