PHP GET not working

Discussion in 'PHP' started by nugis, Apr 14, 2009.

  1. #1
    
    # <?php require_once "../dbcon.php";
    # echo $_GET["picnr"]; ?>
    # <?php if (isset($_POST['define_url'])) {
    #     $result = mysql_query("INSERT INTO booklinks (username, picnr, url)
    # VALUES ('".$_COOKIE['username']."', '".$_GET["picnr"]."', '".$_POST['href']."')");
    # header("Location: ../engine_bookmarks/edit_books_index.php");
    # } ?>
    #  
    # <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    # <input type="text" name="href" maxlength="1000">
    # <input type="submit" name="define_url" value="Määra">
    # </form>
    
    Code (markup):
    The weird thing about this code is that echoing variable $_GET["picnr"] results in 1. Which is what i want. But after inserting it into the DB i see 0 as the inserted value. I did the echoing part just to know if the value is there.
    Helpz :confused:
     
    nugis, Apr 14, 2009 IP
  2. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if you use the $_REQUEST array you should not have the problem ?
     
    juust, Apr 14, 2009 IP
  3. rickyray

    rickyray Peon

    Messages:
    65
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Using $_REQUEST is not a good idea, it's insecure and so it using the super global $_SERVER['PHP_SELF'] to submit the form to itself. For development purpose it's find but not for final output script.

    Why you should not use $_SERVER['PHP_SELF']

    there are other problems with your code also but reading is a good start.
     
    rickyray, Apr 14, 2009 IP
  4. jimbursch

    jimbursch Peon

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    On first glance, I my first suspicion would be a problem with all the quote marks. Could be causing a parsing problem.

    Might try this:
    $picnr = $_GET["picnr"];
    then use $picnr in your sql statement.

    Notice that your GET uses double quotes, but your COOKIE and POST variables use single quotes.
     
    jimbursch, Apr 14, 2009 IP