Why doesnt $_GET ['$example'] Work?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ljking20003
    New Member
    • Jan 2010
    • 2

    #1

    Why doesnt $_GET ['$example'] Work?

    hi
    dont really know how to explain it so i'll just show the code

    what i need it to do is
    $_get information from the url that is stored in a variable
    for example
    abc=1,bcd=2

    (load abc and bcd in a while loop from database)
    set $name=$_get[$variable]
    display the name then wipe before movin on to the next variable in the database


    this is where the information is sent
    Code:
    while($row = mysql_fetch_array($result)) {
    $ddriver=$row['driver'];
    echo"<br> Enter $ddriver 's Hours For $date <input type='text' name='$ddriver' value='0' size='5'>";
    };
    echo"<br><input type='submit' value='Generate Preview Profit Loss Sheet For $date'></form>";
    and this is the section where its supposed pick it up

    Code:
    $query="SELECT * FROM `drlist`";
    $result=mysql_query($query);
    while($row = mysql_fetch_array($result)) {
    $dname=$row['dname'];
    $dhourrate=$row['dhourrate'];
    $ddriver=$_GET [$dname];
    echo "$dname,$ddriver, test ,$dhourrate";
    if ($ddriver<>'') {
    $driverwork=$ddriver-0.75;
    $drivercost=$driverwork*$dhourrate;
    															
    echo " Driver $dname, Hours After Break = $driverwork, Driver Cost @ $dhourrate per hour = 				
    $drivercost";}; 
    $ddriver='';
    };
    															
     
    };
    i know this method isnt very secure but at the moment i just need this working can anyone help
    Last edited by ljking20003; Jan 7 '10, 04:40 PM. Reason: clairification
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    $_GET [$dname]; <--- Why is there a space between $_GET and [$dname] ?

    Also, you didn't tell us where the code breaks, What's the error you get if any. Is error_reporting turned on?



    Dan

    Comment

    • ljking20003
      New Member
      • Jan 2010
      • 2

      #3
      sorry that was just a typo there is no space in the code as for code breaks, i dont get any errors with reporting on, the rest of the page loads fine ive used echos to display all the variables after loading however the $_GET[$dname]; is the only one it doesnt retrieve is there a different way of formating the [$dname]; or something due to it being a variable not a set name?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Check the validity of your claim that $_GET[$dname] exists.

        Code:
        if (!isset($_GET[$dname])) {
             printf("%s does not exist in the URL (%s",
                     $dname, $_SERVER['QUERY_STRING']);
        }
        If you receive the printed error, then you know you are doing something wrong.

        Also post the results of that test.

        Mark.

        Comment

        Working...