PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Okay so I'm writing a little script to update rows of a database.
I am able to update the records but ONLY with numbers. It is not allowing me to update with alpha chars, and this has nothing to do with MYSQL as far as I know. All of my fields are set properly ie: category is VARCHAR.
Sorry, I guess I missed that. What is the output of mysql_error()?
ah... wait a minute... you're not quoting your string. I missed it because of the way you have it formatted, but that's the problem.
$insert = "UPDATE parts SET category = ".$_POST['category']." WHERE id = ".$id."";
//this last "" is meaningless as well. It could be ended by :: id = ".$id;
//although you should still end it with a semicolon
//It should be:
$insert = "UPDATE parts SET category = '{$_POST['category']}' WHERE id = '{$id}';";
//(or, if you prefer:)
$insert = "UPDATE parts SET category = '".$_POST['category']."' WHERE id = '".$id."';";
//assuming you're only updaing a single entry (that `id` is unique), you should end your query with LIMIT 1:
$insert = "UPDATE parts SET category = '{$_POST['category']}' WHERE id = '{$id}' LIMIT 1;";
//Though many people don't use this notation, I personally always quote (backtick/grave) my tables and columns as well:
$insert = "UPDATE `parts` SET `category` = '{$_POST['category']}' WHERE `id` = '{$id}' LIMIT 1;";
Always, always quote your data in SQL inserts whether the type is numeric or otherwise.
(Ahem.. I'm going to feel dumb if this doesn't fix things..)