Jump to content

Mysql Update Help Need


marcus

Recommended Posts

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]
<?php

function 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
};
?>
<?php
if($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]
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.