Jump to content


Photo

form not working for some reason :S


  • Please log in to reply
5 replies to this topic

#1 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 16 August 2006 - 10:56 PM

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
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>";
  
}

productadd.php?mode=add_comp_cat
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>";

}

}


#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 16 August 2006 - 11:01 PM

Not sure if you can use GET and POST methods at the same time?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#3 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 16 August 2006 - 11:05 PM

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

#4 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 16 August 2006 - 11:26 PM

Of course it could always be that classic error,

if ($mode = "add_comp_cat")

when you actually meant

if ($mode == "add_comp_cat") 

or perhaps even
if ($_GET["mode"] == "add_comp_cat") 

Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#5 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 16 August 2006 - 11:31 PM

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" />
follow me on twitter @PHPsycho

#6 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 17 August 2006 - 12:21 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users