SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with $_GET variable losing value within script

    I have a serious problem with my $item variable.When it enters the if(isset($_POST['btnSubmit'])) {} block, the variable $item loses its value.
    I check it with two lines of echo statment;

    this takes place before the insert,when the page loads and it prints the numeric value which is correct
    PHP Code:
    echo "this item:".$item
    this takes place after the insert and is empty and i believe that is why the insert statment for product_id is not inserting nothing.
    PHP Code:
    if($rate_sql){
        echo 
    "this item:".$item;} 
    check below for the full code
    PHP Code:
    require 'functions/functions.inc.php'//this file includes the pdb() function for removing quotes

    $item $_GET['product_id'];

    if(isset(
    $_POST['btnSubmit'])) {

        
    $ip pdb($_SERVER['REMOTE_ADDR']);
        
    $rating pdb($rating);
        
    $usercheck pdb($usercheck);
        
    $title pdb($title);
        
    $review pdb($review);
        
    $date_added date("F j, Y");
        
    $tags pdb($tags);
        
    $item pdb($item);
        
    $user pdb($user);
        
    $name pdb($facebook_result[0]['name']);

        
    // escape any harmful code and prevent sql injection
    $ip mysql_real_escape_string($ip);
    $rating mysql_real_escape_string($rating);
    $usercheck mysql_real_escape_string($usercheck);
    $title mysql_real_escape_string($title);
    $review mysql_real_escape_string($review);
    $date_added mysql_real_escape_string($date_added);
    $item mysql_real_escape_string($item);
    $user mysql_real_escape_string($user);
    $name mysql_real_escape_string($name);

     
    // removal all code from data
    $ip strip_tags($ip);
    $rating strip_tags($rating);
    $usercheck strip_tags($usercheck);
    $review strip_tags($review);
    $date_added strip_tags($date_added);
    $item strip_tags($item);
    $title strip_tags($title);
    $user strip_tags($user);
    $name strip_tags($name);

    // now we insert it into the database
    $sql "INSERT INTO ratings (ip_address, rating, product_id, fb_uid, title, review, reviewer, date_added)
    VALUES ('" 
    $ip "', '" $rating "', '" $item "', '" $user "', '" $title "', '" $review "','" $name "','" $date_added "' )";
    $rate_sql mysql_query($sql) or die('Error : ' mysql_error());

    }


    echo 
    render_header();
    echo 
    "this item:".$item;

    if(
    $rate_sql){
        echo 
    "this item:".$item;

    so can someone help me out here,why my $item lost is value within the insert block of code

  2. #2
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry guys I've fixed it.

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    in case anyone else has a similar problem, what was the solution?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Zealot My220x's Avatar
    Join Date
    Dec 2008
    Location
    United Kingdom
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How did you fix it?

  5. #5
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I included the $_GET variable in a hidden form input tag like this :
    PHP Code:
    <input type="hidden" name="product" value="<?php echo $_GET['product_id'];?>" />
    so that when retrieving the $_POST variables, the $_GET variable would now be
    $_POST['product']


Bookmarks

Posting Permissions

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