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