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? Quote 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']; ?> Quote 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/70696-a-mysql-query/#findComment-355374 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.