Nothadoth Posted August 16, 2006 Share Posted August 16, 2006 Every time I use this form to enter data in to my table in the database, it gives the error I wrote saying: "Error! You did not fill in the form properly! Please click back and try again."Could someone please take a look at it?addproduct.php?mode=add_comp_cat[code]if ($_GET['mode'] == "add_comp_cat") { print "<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse; margin-top: 7' bordercolor='#000000' width='100%'> <tr> <td width='100%' height='27' background='".$ROOT."styles/images/contbar.jpg'><center><span class='t1'>ADD COMPUTING CATEGORY TO THE DATABASE</span></center></td> </tr> <tr> <td width='100%'><table border='0' cellpadding='0' cellspacing='5' style='border-collapse: collapse' width='100%'> <tr> <td width='100%'><div align='center'> <center><table border='0' cellpadding='5' cellspacing='0' style='border-collapse: collapse' width='100%'> <tr> <td width='100%'><div align='center'><form method='POST' action='productadd.php?mode=add_comp_cat'> <table border='0' cellpadding='2' cellspacing='0' style='border-collapse: collapse'> <tr> <td width='200' height='22' align='center'><span class='t2'>Name</span></td> <td height='22'><input type='text' name='name' size='20'></td> </tr> <tr> <td width='200' height='22' align='center'><span class='t2'>Parent</span></td> <td height='22'><select name='parent'> "; mysql_connect('localhost','noth','disc89'); mysql_select_db('noth_igbltduk'); $querycates = mysql_query("SELECT * FROM categories ORDER BY name ASC");while($cates = mysql_fetch_array($querycates)) { print "<option value='".$cates['name']."'>".$cates['name']."</option>"; } print "</select></td> </tr> <tr> <td width='200' height='22' align='center'><span class='t2'>Thumb Image</span></td> <td height='22'><input type='text' name='thumb_img' size='20'></td> </tr> </table> <input type='submit' value='Add Category' name='add_comp_cat'><input type='reset' value='Reset Fields' name='resetphones'></form></div></td> </tr> </table> </center></div></td> </tr></table></td> </tr></table>"; } [/code]productadd.php?mode=add_comp_cat[code]if ($mode = "add_comp_cat") { if ($_POST['name'] == "" OR $_POST['parent'] == "" OR $_POST['thumb_img'] == "") { print "<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#000000' width='100%'> <tr> <td width='100%' height='27' background='".$ROOT."styles/images/contbar.jpg'><center><span class='t1'>ERROR ADDING TO DATABASE</span></center></td> </tr> <tr> <td width='100%'><div align='center'> <center> <table border='0' cellpadding='5' cellspacing='0' style='border-collapse: collapse' width='100%'> <tr> <td width='100%'><span class='t2'>Error! You did not fill in the form properly! Please click back and try again.</span></td> </tr> </table> </center></div></td> </tr></table>";} else { print "<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#000000' width='100%'> <tr> <td width='100%' height='27' background='".$ROOT."styles/images/contbar.jpg'><center><span class='t1'>ADDED TO THE DATABASE SUCCESSFULLY!</span></center></td> </tr> <tr> <td width='100%'><div align='center'> <center> <table border='0' cellpadding='5' cellspacing='0' style='border-collapse: collapse' width='100%'> <tr> <td width='100%'>"; $name = $_POST['name']; $parent = $_POST['parent']; $thumb_img = $_POST['thumb_img']; mysql_connect("localhost", "$dbuser", "$dbuserpass") or die(mysql_error());mysql_select_db('noth_igbltduk') or die(mysql_error()); mysql_query("INSERT INTO `productcategories_comp_sub` (name, parent, thumb_img) VALUES ('$name', '$parent', '$thumb_img')") or die(mysql_error());Print "<span class='t2'>The following information was correctly entered in to the database:<br><br><B>Name:</B> ".$name."<br><B>Parent:</B> ".$parent."<br><B>Thumb Image URL:</B> ".$thumb_img."</span>"; print "</td> </tr> </table> </center></div></td> </tr></table>";}}[/code] Link to comment https://forums.phpfreaks.com/topic/17782-form-not-working-for-some-reason-s/ Share on other sites More sharing options...
king arthur Posted August 16, 2006 Share Posted August 16, 2006 Not sure if you can use GET and POST methods at the same time? Link to comment https://forums.phpfreaks.com/topic/17782-form-not-working-for-some-reason-s/#findComment-75944 Share on other sites More sharing options...
Nothadoth Posted August 16, 2006 Author Share Posted August 16, 2006 yeah because it works on all my other scripts.just obviously i've missed or done something really silly here that i haven't realised. And i have too much to do in little time to re-do it.so i thought i'd post it here because I couldn't figure it out Link to comment https://forums.phpfreaks.com/topic/17782-form-not-working-for-some-reason-s/#findComment-75946 Share on other sites More sharing options...
king arthur Posted August 16, 2006 Share Posted August 16, 2006 Of course it could always be that classic error,[code]if ($mode = "add_comp_cat")[/code]when you actually meant[code]if ($mode == "add_comp_cat") [/code]or perhaps even[code]if ($_GET["mode"] == "add_comp_cat") [/code] Link to comment https://forums.phpfreaks.com/topic/17782-form-not-working-for-some-reason-s/#findComment-75951 Share on other sites More sharing options...
ToonMariner Posted August 16, 2006 Share Posted August 16, 2006 I'm not to comfortable with the form posting data to a url with parameters in it.Why not just have pots data going to that script? simply add a hiden field like so<input type="hidden" name="mode" id="mode" value="add_comp_cat" /> Link to comment https://forums.phpfreaks.com/topic/17782-form-not-working-for-some-reason-s/#findComment-75953 Share on other sites More sharing options...
Nothadoth Posted August 17, 2006 Author Share Posted August 17, 2006 Thank you, works.ToonMariner: Yeah I know what you mean. But it means rescripting a lot of stuff to do that because I have done it for a lot of things. I'll keep it in mind though. Link to comment https://forums.phpfreaks.com/topic/17782-form-not-working-for-some-reason-s/#findComment-75965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.