marcus Posted November 24, 2006 Share Posted November 24, 2006 Ok, I'm just making a news system with categories and what not. But I keep getting the mysql_error [code]Unknown column 'test2' in 'field list'[/code]Test 2 was the new category I was trying to name it.when trying to update the category name. Below is the code, and the main focus is on the bottom of the code[code]<?phpfunction category(){$catsql = "SELECT * FROM cat";$catres = mysql_query($catsql);$num = mysql_numrows($catres);if($num == 0){echo "No Categories, <a href=".'news.php?act=cat'.">click here</a> to add one";}else {echo "Category: <select name=category>";while ($row1 = mysql_fetch_array($catres, MYSQL_BOTH)) { print "<option value=$row1[id]>$row1[catname]</option>";}mysql_free_result($catres);echo "</select>";}}if(!$act){?><table border=0 cellspacing=2 cellpadding=2><tr><td colspan=2 align=right><h3>Add A Category</h3><form name=addcat method=post action="<?=$PHP_SELF?>"><tr><td class=cA>Category Name:<td><input type=text name=catname size=30><tr><td colspan=2 align=left><input type=hidden name=action value=addcat><input type=submit value="Add Category"></form><tr><td colspan=2 align=right><h3>Rename A Category</h3><form name=addcat method=post action="<?=$PHP_SELF?>"><tr><td class=cA><? category() ?><td>Rename To:<input type=text name=newcatname><tr><td colspan=2><input type=hidden name=action value=rename><input type=submit value="Rename"></form></table><?php};?><?phpif($act == addcat){$catname = $_POST[catname]; if(!$catname){ echo "You did not specify a category name"; }else{ $add = "INSERT INTO cat (`catname`) VALUES('$catname')"; $addres = mysql_query($add) or die(mysql_error()); echo "Category $catname has been added to the categories list"; };};if($act == rename){$newcat = $_POST[newcatname];$newid = $_POST[category]; if(!$newcat){ echo "You did not specify a new category name ID #$newid"; }else{ $ren = "UPDATE `cat` SET catname =$newcat WHERE id='$newid'"; $rena = mysql_query($ren) or die(mysql_error()); echo "Category ID #$newid has been changed to $newcat"; };};?>[/code] Quote Link to comment Share on other sites More sharing options...
ataria Posted November 24, 2006 Share Posted November 24, 2006 $ren = mysql_query("UPDATE `cat` SET `catname`='{$newcat}' WHERE `cat` . `id`='{$newid}'"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.