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.
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.
Should you have a method attribute in the form tag? What happens anyway? Does the page load, do you get a blank screen?
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.
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
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.
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:
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
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:
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
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\">