SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET variables to database not working

    I have a page that receives variables in the URL, like so:
    ...ordering.php?id=sky3&set_albumName=Smith

    in the receiving page, I retrieve the vars like this:

    Code:
    $image1 = $_GET['id']; 
    $client1 = $_GET['set_albumName'];
    Then I'm trying to stuff these into a MySQL db like so:

    Code:
    $query = "INSERT INTO dd_order (client, image) VALUES ('$client1', '$image1')";
    but it ain't workin'. I can echo $image1 and $client1 to the screen, so the values must be there, but they don't show up in my database fields. My other vars that I define from a form on this page get inserted fine; just not these two getting passed in. Anyone help me out? I don't understand why I can echo it to the screen, but not insert it into the database! I can assign the value to another variable, echo that to the screen, but if I plug it into the query, it still won't insert. wtf? I've tried getting the vars with $_GET, $_POST, $HTTP_GET_VARS... etc.


    Here's the whole page:
    Code:
    <html> 
    <head> 
    <title>ordering</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    
    </head> 
    
    <body bgcolor="#FFFFFF"> 
    <form action="<?php echo $PHP_SELF ?>" method="POST"> 
    
    <?php 
    
    
    require("dd_upload_inc.php"); 
    require("dd_functions.php"); 
    
    function check_mysql() 
    { 
    if (mysql_errno() > 0) 
    { 
    die("<BR> MySQL error " . mysql_errno() . ": " . mysql_error()); 
    } 
    } 
    
    $db = mysql_connect($host, $usr, $pw); 
    if (!$db) 
    { 
    die("Failed to open connection to MySQL server."); 
    } 
    
    mysql_select_db("$dbname"); 
    check_mysql(); 
    
    //get posted vars... tried a number of variations here... 
    
    $image1 = stripslashes($_GET['id']); 
    $client1 = $_GET['set_albumName']; 
    echo $client1; //echo works fine!!! but won't write to database... 
    
    if (isset($placeorder)) 
    { 
    $query = "INSERT INTO dd_order"."(order_date, client, image, quantity, size, priceper, total, duedate) VALUES ('$order_date1', '$client1', '$image1', '$quantity1', '$size1', '$priceper1', '$total1', '$duedate1')"; 
    
    $result = mysql_query($query); 
    check_mysql(); 
    } 
    
    $order_date1 = trim($order_date1); 
    $client1 = trim($client1); 
    $image1 = trim($image1); 
    $quantity1 = trim($quantity1); 
    $size1 = trim($size1); 
    $priceper1 = trim($priceper1); 
    $total1 = trim($total1); 
    $duedate1 = trim($duedate1); 
    
    
    ?> 
    
    <b>Order Prints <br> 
    <br> 
    </b> 
    <table border="0" cellspacing="0" cellpadding="5"> 
    <tr> 
    <td align="right">Quantity:</td> 
    <td> 
    <input type="text" name="quantity1" size="4" maxlength="4" <?php echo "VALUE=\"$quantity1\"" ?>> 
    </td> 
    </tr> 
    <tr> 
    <td align="right">Size:</td> 
    <td> 
    <select name="size1"> 
    <option selected>Choose...</option> 
    <option value="wallets">Wallets</option> 
    <option value="4x6">4 x 6</option> 
    <option value="5x7">5 x 7</option> 
    <option value="8x10">8 x 10 </option> 
    <option value="11x14">11 x 14 </option> 
    <option value="16x20">16 x 20</option> 
    <option value="20x24">20 x 24</option> 
    <option value="24x30">24 x 30</option> 
    <option value="30x40">30 x 40</option> 
    <option value="30x48">30 x 48</option> 
    <option value="30x60">30 x 60</option> 
    <option value="30x72">30 x 72</option> 
    <option value="30x84">30 x 84</option> 
    <option value="30x96">30 x 96</option> 
    </select> 
    (larger prints by request)</td> 
    </tr> 
    <tr> 
    <td align="right">Turnaround:</td> 
    <td> 
    <select name="turnaround1"> 
    <option selected>Choose...</option> 
    <option value="1">24-Hour </option> 
    <option value="4">4-Day </option> 
    <option value="7">7-Day </option> 
    </select> 
    </td> 
    </tr> 
    
    </table> 
    <input type="submit" name="placeorder" value="Place Order"> 
    
    
    </form> 
    </body> 
    </html>
    www.skullfarm.com

  2. #2
    SitePoint Zealot rae's Avatar
    Join Date
    Apr 2003
    Location
    bedroom :P
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by skullfarm
    $query = "INSERT INTO dd_order"."(order_date, client, image, quantity....
    Why is it concatenated?
    It produces:

    PHP Code:
    "INSERT INTO dd_order(order_date, client, image,...." 
    Maybe that's the problem (no space after the table name).
    But that's just for the first sight.
    d(o.O)b -- Notice: undefined variable: /me

  3. #3
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, that was originally split over two lines. It has since been fixed, but still no joy
    www.skullfarm.com

  4. #4
    SitePoint Zealot rae's Avatar
    Join Date
    Apr 2003
    Location
    bedroom :P
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm... Is there any error outputted?

    Maybe you don't have insert privilege on mysql?
    First, set error reporting to error_reporting(E_ALL);
    This will show every syntax and some other errors.

    Then a good practise: print your mysql query string in the browser. And then if you have PhpMyAdmin, copy the string and run the query and see what will it cause. Or type that at the mysql command line.

    Then dunno... we will see it.
    d(o.O)b -- Notice: undefined variable: /me

  5. #5
    SitePoint Zealot rae's Avatar
    Join Date
    Apr 2003
    Location
    bedroom :P
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And what about $placeorder?
    Are you sure that returns true?
    PHP Code:
    if (isset($placeorder)) 

    d(o.O)b -- Notice: undefined variable: /me

  6. #6
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope, no errors reported. It does insert some of the other vars, just not the ones passed from the URL. $placeorder returns true on the button click; it inserts the other vars.
    www.skullfarm.com

  7. #7
    SitePoint Addict Messiah's Avatar
    Join Date
    Jun 2001
    Location
    Bloomington, In.
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What data types are the two variables you are having problems with? Can I see an example query string with those two variables set && which doesn't complete the insert? Also, if $image1 is an int, you don't need to single quotes around the var in your query. Try removing those like so:

    PHP Code:
    $query "INSERT INTO dd_order ( client, image ) VALUES ( '$client1', $image1 )"
    Messiah | Ink-Press: web publishing simplified!

  8. #8
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These should just be text strings. My db has them defined as varchar(200). Is that what you are asking me? I'm sorry, I'm not much of a database expert

    like I said, I can echo them to the screen as strings...
    www.skullfarm.com

  9. #9
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is kind of interesting... when I add the line
    Code:
    $client1 = $client1."test";
    after
    Code:
    $client1 = $_GET['set_albumName'];
    it inserts the text "test" into the database... so it seems to me like it is tossing the original value somewhere...
    www.skullfarm.com

  10. #10
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    D'oh! clicking on the submit button causes the form to perform its "action", which was reloading the page and wiping out the passed vars... I removed the "action="<?php echo $PHP_SELF ?>" part, and now it works fine. Whew!

    Thanks for all the help.
    www.skullfarm.com

  11. #11
    SitePoint Zealot rae's Avatar
    Join Date
    Apr 2003
    Location
    bedroom :P
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by skullfarm
    D'oh! clicking on the submit button causes the form to perform its "action", which was reloading the page and wiping out the passed vars... I removed the "action="<?php echo $PHP_SELF ?>" part, and now it works fine. Whew!

    Thanks for all the help.
    Ahh... Uhh.... Ehh...Ohh

    Ok.
    d(o.O)b -- Notice: undefined variable: /me


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
  •