tibberous Posted September 26, 2007 Share Posted September 26, 2007 I have two tables, one called categories, one called files. Categories has three fields: id, categoryname and parent Files has four fields: id, filename, categoryid and categoryname Now, I have a table with all the category id's set - I need to set categoryname = to the categoryname with the id of categoryid. Sorry if that is hard to follow, it is hard to write too. Anyone know how to do this? Link to comment https://forums.phpfreaks.com/topic/70696-a-mysql-query/ Share on other sites More sharing options...
darkfreaks Posted September 26, 2007 Share Posted September 26, 2007 SET categoryname WHERE id='$id' <?php $id=$_GET['category_id']; ?> Link to comment https://forums.phpfreaks.com/topic/70696-a-mysql-query/#findComment-355372 Share on other sites More sharing options...
marcus Posted September 26, 2007 Share Posted September 26, 2007 Deh, dark, you should help him out by stopping out a mysql injection. $id = mysql_real_escape_string($_GET['category_id']); if($id){ if(ctype_digit($id)){ //if you don't have ctype extension on use intval $sql = "SELECT * FROM `table` WHERE `id`='$id'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "ID does not exist!\n"; }else { $sql2 = "UPDATE `table` SET `field`='new_row' WHERE `id`='$id'"; $res2 = mysql_query($sql2) or die(mysql_error()); echo "Updated"; } }else { echo "Invalid ID"; } }else { echo "ID not set"; } Link to comment https://forums.phpfreaks.com/topic/70696-a-mysql-query/#findComment-355374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.