Author Topic: Need help with this code  (Read 443 times)

0 Members and 1 Guest are viewing this topic.

Offline vdcpaladinTopic starter

  • Irregular
  • Posts: 6
    • View Profile
Need help with this code
« on: April 16, 2008, 07:35:35 PM »
Hey guys I have been looking at this code now for a few days around doing other things and I still cant find out why it is not inserting into the mysql database.

Code: [Select]
<html>
   <head>
   <?
        include("./db_connect.php");
        $db = new connection();
        $db->connect();
        $username = $_POST['username'];
$catagory = $_POST['catagoryName'];
$catagoryDesc = $_POST['catagoryDescription'];
   ?>
   </head>

   <body>
<form name="completed" action="admin.php" method = "POST">
   <?
echo "->".$catagory;
echo $catagoryDesc;
if(($catagory == '') || ($catagoryDesc == ''))
{
echo "Did not recieve catagory name or description - update FAILED<br>";
}
else
{
echo "Catagory: ".$catagory."<br>";
echo "Catagory Description: ".$catagoryDesc."<br>";
$query = "INSERT INTO catagory (name,desc) VALUES ('$catagory', '$catagoryDesc');";
echo $query."<BR>";
mysql_query($query) or die('Error - Could not insert catagory into the database');
}
$db->close();
   ?>

       <input type="hidden" name="username" value="<? echo $username; ?>">
</form>

<script type='text/javascript'>
alert("Group <? echo $catagory; ?> as been added to the database");
document.completed.submit();
</script>

   </body>
</html>



Offline tinker

  • Enthusiast
  • Posts: 327
    • View Profile
Re: Need help with this code
« Reply #1 on: April 16, 2008, 08:05:09 PM »
seems ok at first glance?
is it throwing any errors? - try:
Code: [Select]
error_reporting(E_ALL);

just for fun I use this for comparing strings (but its not your prob):
Code: [Select]
strcmp($catagoryDesc, "") == 0)

hmmm not sure?

Offline vdcpaladinTopic starter

  • Irregular
  • Posts: 6
    • View Profile
Re: Need help with this code
« Reply #2 on: April 16, 2008, 08:13:47 PM »
This is the error i get

Error - Could not insert catagory into the database

Offline AP81

  • Enthusiast
  • Posts: 96
    • View Profile
Re: Need help with this code
« Reply #3 on: April 16, 2008, 11:05:37 PM »
You should paste the query into a MySQL front-end and run it...the error is with your query itself.  You syntax is right, so it most probably a spelling mistake.

You can always try this to find out what the error is:
Code: [Select]
$result = mysql_query($query);
if (!$result) {
  die('Error - ' . mysql_error());
}

BTW category is spelt 'category', not 'catagory'