Bee Posted May 13, 2006 Share Posted May 13, 2006 Hi, Does anyone know what's wrong with this form please? It should write data to a database; however, it doesn't.[code]<html><head><title>order website</title></head><body><?php//$Send = $_GET['Send']; if ($Send) { // process form $db = mysql_connect("localhost", "root", ""); if($db == false) echo "Failed to connect!"; if(mysql_select_db("aimredaco",$db)== false) echo "Failed to select database!"; $sql = "INSERT INTO orders (order_ID, name, email, company_name, address, post_code, city, tel, mobile, website, redesign_website, website_to_redesign, no_pages, web_design, flash_graphics, flash_programming, programming, shopping_cart, comments) VALUES (NULL, '$name', '$email', '$company_name', '$address', '$post_code', '$city', '$tel', '$mobile', '$website', '$redesign_website', '$website_to_redesign', '$no_pages', '$web_design', '$flash_graphics', '$flash_programming', '$programming', '$shopping_cart', '$comments')"; $result = mysql_query($sql); echo "Thank you! Information entered.\n";} else{ // display form?><form method="post" action="<?php echo $PHP_SELF?>"><table width="100%" height="0%" border="1" cellpadding="0" cellspacing="0" bordercolor="#999999"> <tr> <td height="833"> <!-- inside table header --> <table width="100%" height="0%" border="0" align="center" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#FFFFFF"> <tr> <td height="2%" colspan="2" valign="middle" background="company/images/index_15.gif" bgcolor="#EFEFEF"><strong><font color="#333333">Order your website</font></strong></td> </tr> <tr> <td height="5%" colspan="2" valign="middle" bgcolor="#EFEFEF"> <p>If you are interested in our services then please fill out the form below to request a quote.</p> <p><br> </p></td> </tr> <tr> <!-- text boxes --> <td width="47%" height="2%" valign="middle" bgcolor="#EFEFEF"> <div align="right"> <div align="right">*Name:</div> </div></td> <td width="53%" bgcolor="#EFEFEF"><span> <input name="name" style="VERTICAL-ALIGN: middle" size="35" /> </span></td> </tr> <!---------------------> <tr> <td width="47%" valign="middle" bgcolor="#EFEFEF"><div align="right"> <div align="right">*Email:</div> </div></td> <td width="53%" height="2%" bgcolor="#EFEFEF" class="style112"><span class="formName style45"> <input name="email" style="VERTICAL-ALIGN: middle" size="35" /> </span></td> </tr> <!---------------------> <tr bgcolor="#FFFFFF" class="style112"> <td width="47%" height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style182"> <div align="right" class="style174">Company:</div> </div></td> <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> <input name="company_name" style="VERTICAL-ALIGN: middle" size="35" /> </span></td> </tr> <!---------------------> <tr> <td width="47%" bgcolor="#EFEFEF" class="style112"><div align="right" class="style183"><span class="style174">Address:</span></div></td> <td width="53%" height="2%" bgcolor="#EFEFEF"><span class="formName style45"> <input name="address" style="VERTICAL-ALIGN: middle" size="35" /> </span></td> </tr> <!---------------------> <tr class="style112"> <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">Postcode:</span></div></td> <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> <input name="post_code" style="VERTICAL-ALIGN: middle" size="35" /> </span></td> </tr> <!---------------------> <tr> <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">City: </span></div></td> <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> <input name="city" class="style174" style="VERTICAL-ALIGN: middle" size="35" /> </span></td> </tr> <!---------------------> <tr class="style112"> <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">Telephone:</span></div></td> <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> <input name="tel" style="VERTICAL-ALIGN: middle" size="35" /> </span></td> </tr> <!---------------------> <tr class="style112"> <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">Mobile: </span></div></td> <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> <input name="mobile" style="VERTICAL-ALIGN: middle" size="35" /> </span></td> </tr> <!---------------------> <tr class="style112"> <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">Website:</span></div></td> <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> <input name="website" style="VERTICAL-ALIGN: middle" size="35" /> </span></td> </tr> <!-- radio buttons> <tr class="style112"> <td height="8%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">What service would you like us to offer?</span></div></td> <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> <input onClick="" type="radio" checked="checked" value="y" name="redesign_website" /><span class="style174">Redesign website</span> <span class="style180"><br /> <input onClick="" type="radio" value="n" name="redesign_website" /><span>New website design</span></span></span><span class="formName style180"><br /> <br /> <!-- text box --> </span><span class="style174">If you choose redesign option, what's your website's address? </span><span class="style178"> </span><span class="formName style45"> <input name="website_to_redesign" style="VERTICAL-ALIGN: middle" value="http://" size="60" /> </span></td> </tr> <!-- combobox --> <tr> <td height="30" bgcolor="#EFEFEF"> <div align="right"><span>Approximately how many pages do you anticipate the site having?</span></div></td> <td width="53%" bgcolor="#EFEFEF"><span> <select style="VERTICAL-ALIGN: middle" name="no_pages"> <option value="">Please select an option.</option> <option value="1">1 page</option> <option value="2to5">2-5 pages</option> <option value="5to10">5-10 pages</option> <option value="10+">10+</option> </select> </span></td> </tr> <!-- checkboxes --> <tr class="style112"> <td height="139" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">What services are you interested in? (Check all that apply)</span></div></td> <td width="53%" valign="baseline" bgcolor="#EFEFEF" class="style112 style180"><dl> <dt><span class="formName "> <input type="checkbox" value="y" name="web_design" /> </span><span class="style179">Web Design</span></dt><dt> <span class="style179"> <input type="checkbox" value="y" name="flash_graphics" />Flash Graphics</span> </dt> <dt> <input type="checkbox" value="y" name="flash_programming" />Flash Programming<br /> <input type="checkbox" value="y" name="programming" />Programming<br /> <input type="checkbox" value="y" name="shopping_cart" />Shopping cart </dt> </dl></td> </tr> <!-- comments textbox --> <tr> <td height="21%" bgcolor="#EFEFEF"> <div align="right"><span>Questions & comments:</span></div></td> <td width="53%" bgcolor="#EFEFEF"><span> <textarea name="comments" cols="50" rows="10" style="VERTICAL-ALIGN: middle"></textarea> </span></td> </tr> <!-- send button --> <tr> <td height="30" bgcolor="#EFEFEF"> </td> <td width="53%" bgcolor="#EFEFEF"><span> <input name="Send" type="Submit" value="Send" /> </span></td> </tr> </table></td> </tr></table></form></body></html><?php}?>[/code] Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/ Share on other sites More sharing options...
michaellunsford Posted May 15, 2006 Share Posted May 15, 2006 if your Order_ID is auto-increment, just leave it out of your INSERT query (instead of sending NULL). See if that works and reply. Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/#findComment-35978 Share on other sites More sharing options...
Bee Posted May 17, 2006 Author Share Posted May 17, 2006 [!--quoteo(post=374020:date=May 15 2006, 10:07 AM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ May 15 2006, 10:07 AM) [snapback]374020[/snapback][/div][div class=\'quotemain\'][!--quotec--]if your Order_ID is auto-increment, just leave it out of your INSERT query (instead of sending NULL). See if that works and reply.[/quote]Thanks for your reply. I took null away; however, it still doesn't write to the table!that field was auto_increment. Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/#findComment-36743 Share on other sites More sharing options...
michaellunsford Posted May 17, 2006 Share Posted May 17, 2006 Don't even send that field.[code] $sql = "INSERT INTO orders (name, email, company_name, address, post_code, city, tel, mobile, website, redesign_website, website_to_redesign, no_pages, web_design, flash_graphics, flash_programming, programming, shopping_cart, comments) VALUES ('$name', '$email', '$company_name', '$address', '$post_code', '$city', '$tel', '$mobile', '$website', '$redesign_website', '$website_to_redesign', '$no_pages', '$web_design', '$flash_graphics', '$flash_programming', '$programming', '$shopping_cart', '$comments')";[/code] Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/#findComment-36746 Share on other sites More sharing options...
Houdini Posted May 20, 2006 Share Posted May 20, 2006 This is commented out //$Send = $_GET['Send'];then unless you have register_globals ON then this wont work if ($Send) and it is a $_POST variable because of the method in your form so try changing if ($Send) to[code]if(isset($_POST['Send'])){[/code]and see what it does. Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/#findComment-37336 Share on other sites More sharing options...
Bee Posted May 21, 2006 Author Share Posted May 21, 2006 [!--quoteo(post=375409:date=May 19 2006, 07:54 PM:name=Houdini)--][div class=\'quotetop\']QUOTE(Houdini @ May 19 2006, 07:54 PM) [snapback]375409[/snapback][/div][div class=\'quotemain\'][!--quotec--]This is commented out //$Send = $_GET['Send'];then unless you have register_globals ON then this wont work if ($Send) and it is a $_POST variable because of the method in your form so try changing if ($Send) to[code]if(isset($_POST['Send'])){[/code]and see what it does.[/quote]Thank you:)That's slightly worked. it created a new record in the table, but left all fields empty except from the auto_increment PK. Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/#findComment-37790 Share on other sites More sharing options...
AndyB Posted May 21, 2006 Share Posted May 21, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]That's slightly worked. it created a new record in the table, but left all fields empty except from the auto_increment PK.[/quote]Probably because all of the data POSTed from the form were not abstracted from the $_POST array. Your script assumes that register_globals is ON (the default in much earlier versions of php and/or found in outdated scripts). You'll need to retrieve each of the POSTed values using a syntax such as:[code]$name = $_POST['name'];[/code]That should work for you, although there are faster/better ways of doing it. Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/#findComment-37809 Share on other sites More sharing options...
Bee Posted May 22, 2006 Author Share Posted May 22, 2006 [!--quoteo(post=375894:date=May 21 2006, 06:31 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 21 2006, 06:31 PM) [snapback]375894[/snapback][/div][div class=\'quotemain\'][!--quotec--]Probably because all of the data POSTed from the form were not abstracted from the $_POST array. Your script assumes that register_globals is ON (the default in much earlier versions of php and/or found in outdated scripts). You'll need to retrieve each of the POSTed values using a syntax such as:[code]$name = $_POST['name'];[/code]That should work for you, although there are faster/better ways of doing it.[/quote]It would help very much if you can show me a faster better way of doing it actually.Thanks. Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/#findComment-37900 Share on other sites More sharing options...
AndyB Posted May 22, 2006 Share Posted May 22, 2006 [code]if (isset($_POST['Send'])) { // retrieve all POSTed variables foreach ($_POST as $key=>$val) { $$key = trim(strip_tags($val)); // remove spaces at ends and strip html/php tags from input } ... the rest of your form processing ...[/code] Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/#findComment-37950 Share on other sites More sharing options...
Bee Posted June 1, 2006 Author Share Posted June 1, 2006 [!--quoteo(post=376035:date=May 22 2006, 09:21 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 22 2006, 09:21 AM) [snapback]376035[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]if (isset($_POST['Send'])) { // retrieve all POSTed variables foreach ($_POST as $key=>$val) { $$key = trim(strip_tags($val)); // remove spaces at ends and strip html/php tags from input } ... the rest of your form processing ...[/code][/quote]Thank you for that it worked well with it. I wonder why you used two $$ on key? Link to comment https://forums.phpfreaks.com/topic/9597-help-with-form/#findComment-41047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.