Jump to content

Need help with this code


vdcpaladin

Recommended Posts

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.

 

<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>


Link to comment
Share on other sites

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:

$result = mysql_query($query);
if (!$result) {
  die('Error - ' . mysql_error());
}

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.