vdcpaladin Posted April 16, 2008 Share Posted April 16, 2008 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 More sharing options...
tinker Posted April 17, 2008 Share Posted April 17, 2008 seems ok at first glance? is it throwing any errors? - try: error_reporting(E_ALL); just for fun I use this for comparing strings (but its not your prob): strcmp($catagoryDesc, "") == 0) hmmm not sure? Link to comment https://forums.phpfreaks.com/topic/101456-need-help-with-this-code/#findComment-519006 Share on other sites More sharing options...
vdcpaladin Posted April 17, 2008 Author Share Posted April 17, 2008 This is the error i get Error - Could not insert catagory into the database Link to comment https://forums.phpfreaks.com/topic/101456-need-help-with-this-code/#findComment-519013 Share on other sites More sharing options...
AP81 Posted April 17, 2008 Share Posted April 17, 2008 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 https://forums.phpfreaks.com/topic/101456-need-help-with-this-code/#findComment-519125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.