Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    PHP/MySQL If Trouble

    Ok i need help with this:

    PHP Code:
    <?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

  • #2
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New Coder
    Join Date
    Dec 2007
    Location
    UK
    Posts
    41
    Thanks
    1
    Thanked 7 Times in 7 Posts
    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 Code:
    <?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

  • Users who have thanked tonyyeb for this post:

    the-dream (01-01-2008)

  • #4
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Would it matter if there were spaces ( %20 ) in my get eg game.php?game=Assassins%20Creed ????

  • #5
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    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!!!

  • #6
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    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 Code:
    <?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);
    ?>

  • #7
    New Coder
    Join Date
    Dec 2007
    Location
    UK
    Posts
    41
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by the-dream View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •