Jump to content

A mysql query


tibberous

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.