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
https://forums.phpfreaks.com/topic/101456-need-help-with-this-code/
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'

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.