Frustrating PHP Problem

Discussion in 'PHP' started by RichardKnox, Oct 21, 2006.

  1. #1
    Hello.

    Im here to tell you about this PHP problem I am having that has cause me so much stress. The problem is the form doesnt submit to the database.

    Code for processauction.php

    
    <link rel="stylesheet" href="usv2.css" type="text/css">
    
    <?
    
    
    ob_start ();
    include ("config.php");
    
    $username = $logged["username"];
    $timel = $_GET["timel"];
    $category = $_GET["category"];
    $sprice = $_GET["sprice"];
    $bin = $_GET["bin"];
    $descr = $_GET["descr"];
    
    //insert the values
    $query = mysql_query("INSERT INTO auctions (username, timel, category, sprice, bin, descr) VALUES ('$username','$timel', '$category','$sprice','$bin','$descr')");
       
    echo "<strong>$logged[username]</strong> you have submitted a new auction. Please let our administrators verify this.";
    ?> 
    
    PHP:
    Code for Newauction.php

    
    <link rel="stylesheet" href="usv2.css" type="text/css">
    
    <?
    
    ob_start();
    
    include ("config.php");
    
    if ($logged[username])
    {
    
    echo ("<div align=\"center\"><p><b>Add A New Auction</b><br/>
    You are logged in as $logged[username].</p>
     
     
    <form action=\"processauction.php\" name=\"auction\">
    <p>Auction Name:<br/>
    <input type=\"text\" size=\"40\" maxlength=\"70\" name=\"aname\" ><br /><br />
     
    Time Limit (days):<br/>
    <input type=\"text\" size=\"40\" maxlength=\"70\" name=\"timel\" ><br/><br/>
     
    Category:<br/>
    <select name=\"category\" id=\"type\" width=\"40\" style=\"border: 1px solid grey;\">
     
    <option>Rares</option>
    <option>Super Rares</option>
    <option>Posters</option>
    <option>Plants</option>
    <option>Other</option>
    </select><br /><br />
     
    Starting Price:<br/>
    <input type=\"text\" size=\"40\" maxlength=\"70\" name=\"sprice\" ><br /><br />
     
    Buy It Now Price:<br/>
    <input type=\"text\" size=\"40\" maxlength=\"70\" name=\"bin\" ><br /><br />
     
    Item Description:<br/>
    <input type=\"text\" size=\"40\" name=\"descr\" style=\"height: 200px;\"><br /><br />
     
    <input type=\"submit\" value=\"Submit\"></form> ");
    }
     
    else {
    echo ("Your not logged in.");
    }
     
    ?> 
    
    PHP:
    Thanks in advance for the help im sure im gonna get.
     
    RichardKnox, Oct 21, 2006 IP
  2. aditya_sfs

    aditya_sfs Peon

    Messages:
    2,271
    Likes Received:
    389
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can u give the structure of auctions table
     
    aditya_sfs, Oct 21, 2006 IP
  3. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #3
    Is your url reflecting the form properties?

    For example are you seeing

    processauction.php?username=???&time1=???

    ect.

    To me it appears like it should work but I am guessing without seeing the site you are have a _POST _GET issue.
     
    aaron_nimocks, Oct 21, 2006 IP
  4. sitestem

    sitestem Well-Known Member

    Messages:
    117
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    138
    #4
    Should you have a method attribute in the form tag?

    What happens anyway? Does the page load, do you get a blank screen?
     
    sitestem, Oct 21, 2006 IP
  5. speedwagon

    speedwagon Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yeah it seems like you should be using $_POST instead of $_GET in your processauction.php
     
    speedwagon, Oct 21, 2006 IP
  6. RichardKnox

    RichardKnox Peon

    Messages:
    209
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well it says its been submitted to the auctions table, but then when I visit my display auctions page it doesnt show up and when I browse the table in PHPmyAdmin it hasnt submitted properly. All the fields are correct for the table, thats all I can say.
     
    RichardKnox, Oct 22, 2006 IP
  7. dfsweb

    dfsweb Active Member

    Messages:
    1,587
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    88
    #7
    That's right. You should be using "POST" and not "GET". $_GET is used for getting command line arguments whereas you will need $_POST in this case. So, simply replace GET by POST and this should work for you.
    Regards,
    dfsweb
     
    dfsweb, Oct 22, 2006 IP
  8. RichardKnox

    RichardKnox Peon

    Messages:
    209
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It still doesnt work when I use post. I originally had POST tried GET but neither work. It just doesnt submit to the database while all my other pages (register etc) do. All my connect files are fine and all the fields are fine. This has me and most people totally stumped.
     
    RichardKnox, Oct 22, 2006 IP
  9. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #9
    This has nothing to do with method you're using. If you want to use POST (recommended) replace this:

    <form action=\"processauction.php\" name=\"auction\">
    HTML:
    with this:

    <form action=\"processauction.php\" name=\"auction\" method=\"post\">
    HTML:

    
    <link rel="stylesheet" href="usv2.css" type="text/css">
    
    <?
    
    
    ob_start ();
    include ("config.php");
    
    $username = mysql_real_escape_string($logged["username"]);
    $timel = mysql_real_escape_string($_POST["timel"]);
    $category = mysql_real_escape_string($_POST["category"]);
    $sprice = mysql_real_escape_string($_POST["sprice"]);
    $bin = mysql_real_escape_string($_POST["bin"]);
    $descr = mysql_real_escape_string($_POST["descr"]);
    
    //insert the values
    $query = mysql_query("INSERT INTO auctions (username, timel, category, sprice, bin, descr) VALUES ('" . $username . "','" . $timel . "','" . $category . "','" . $sprice . "','" . $bin . "','" . $descr . "')");
    
    if(!$query)
    {
       echo '<p style="color: red; font-weight: bold;">Error: ' . mysql_error() . '</p>';
    }
    else
    {
       echo "<strong>$logged[username]</strong> you have submitted a new auction. Please let our administrators verify this.";
    }
    
    ?> 
    
    PHP:
     
    SoKickIt, Oct 22, 2006 IP
  10. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #10
    Although there's not much difference, but try the code below:

    $query ="INSERT INTO `auctions` (username, timel, category, sprice, bin, descr) VALUES ('$username','$timel', '$category','$sprice','$bin','$descr')";
    $rst= mysql_query($query);

    Replace your insert query with the code above and see if it works.
    You must also add some code to check if the submitted values are correct, safe or not.

    Hope that helps you.
    Bye :)
     
    JEET, Oct 22, 2006 IP
  11. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #11
    After what everybody sayd to you, change the query to this :
    
    $query = mysql_query("INSERT INTO `auctions` (`username`, `timel`, `category`, `sprice`, `bin`, `descr`) VALUES ('$username','$timel','$category','$sprice','$bin','$descr')");
    
    PHP:
     
    Morishani, Oct 22, 2006 IP
  12. dfsweb

    dfsweb Active Member

    Messages:
    1,587
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    88
    #12
    I don't see any connect strings in the file you have shown us here. I guess you have removed these?? If not, you know that you have to connect to the database (and select the database) before you can run queries.
    Regards,
    dfsweb
     
    dfsweb, Oct 22, 2006 IP
  13. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #13
    Yep you have to use your connection together with your query
    and add post to your form

    <form action=\"processauction.php\" name=\"auction\" method=\"post\">
     
    php-lover, Oct 23, 2006 IP