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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Php Function Help

    I'm calling a php function that should equip your item, but it doesn't. Maybe I'm trying to hard or not doing it right at all but this is my code:

    User clicks the link, it reloads the page, and calls the equipFunction()
    Code:
    <a href='inventory.php?id=$_SESSION[Inv1]'>Equip</a>
    Function:
    PHP Code:
    <?php
    if(isset($_GET['id']) && $_GET['id'] != "")

    function 
    equipGear()
    {
    $_SESSION['Inv1'] = $_GET['id'];

    $sql "SELECT Type FROM gear WHERE Name = '$_SESSION[Inv1]'" or die(mysqli_error($con));
    $type mysqli_query($con$sql);
    $Type mysqli_fetch_assoc($type);
    $_SESSION['Type'] = $Type['Type'];

    if(
    $_SESSION['Type'] == "Weapon")
    {
    $sql "UPDATE users SET Weapon = '$_SESSION[Inv1]' WHERE Username = '$_SESSION[Username]'";
    $sql "UPDATE inventory SET Inv1 = '$_SESSION[Weapon]' WHERE Username = '$_SESSION[Username]'";
    }
    }
    }
    ?>
    What I'm I doing wrong? Thanks ^_^
    Last edited by VIPStephan; 06-03-2014 at 04:32 PM. Reason: restored original post

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    <a href='inventory.php?id=$_SESSION[Inv1]'>Equip</a>
    Is that your actual code? If so, you may need to change it to
    PHP Code:
    <a href='inventory.php?id=<?php echo $_SESSION[Inv1];?>'>Equip</a>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Is that your actual code? If so, you may need to change it to
    PHP Code:
    <a rel='nofollow' href='inventory.php?id=<?php echo $_SESSION[Inv1];?>'>Equip</a>
    When I change it to that I get this in the url:
    Code:
    http://localhost/inventory.php?id=%3C?php%20echo%20Axe;?%3E
    and still nothing happens :/

    but the way I have it I get this:
    Code:
    http://localhost/inventory.php?id=Axe

  • #4
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Used echo to see how far the code executes and it makes it to the first echo but no further.

    PHP Code:
    <?php
    if(isset($_GET['id']) && $_GET['id'] != "")

    echo 
    "<h1>If statement</h1>";
    function 
    equipGear()
    {
    echo 
    "<h1>Inside function</h1>";
    $_SESSION['Inv1'] = $_GET['id'];
    echo 
    "<h1>Session</h1>";
    $sql "SELECT Type FROM gear WHERE Name = '$_SESSION[Inv1]'" or die(mysqli_error($con));
    echo 
    "<h1>Sql</h1>";
    $type mysqli_query($con$sql);
    echo 
    "<h1>type</h1>";
    $Type mysqli_fetch_assoc($type);
    echo 
    "<h1>Type</h1>";
    $_SESSION['Type'] = $Type['Type'];
    echo 
    "<h1>Session Type</h1>";
    if(
    $_SESSION['Type'] == "Weapon")
    {
    $sql "UPDATE users SET Weapon = '$_SESSION[Inv1]' WHERE Username = '$_SESSION[Username]'";
    $sql "UPDATE inventory SET Inv1 = '$_SESSION[Weapon]' WHERE Username = '$_SESSION[Username]'";
    }
    }
    }
    ?>

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    User written functions consist of two parts, the function definition and the function call. Your code only contains the function definition. You are never calling your function.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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