Jump to content

[SOLVED] Insert Multiple Rows Using a Textarea With Linebreaks


iwpg

Recommended Posts

Hi guys, I have been pulling my hair out trying to find a good example on this.  ??? I know that arrays play the main theme in the function, and I am an array flunkie.  ::)

 

I have a textarea, where I am inserting 1 item per line and I am trying to get it to upload to my mysql database. This is kind of like the Google Adwords "add keywords" function.

 

I also need to be able to remove selected values once they're in the db using a checkbox.

 

I just have no way of handling the submitted data, and inserting it. Any help is GREATLY appreciated.

 

Thanks, Mike

 

 

Thanks for the much needed help. The insert new records function is working perfectly. Many thanks...

 

Now, I am having trouble removing multiple records by using a checkbox. This is what I have:

 

  $id = array();

  $id = $_POST['kwcb'];

 

  if (count($id) > 0)

  {

    foreach ($id as $removeid)

    {

      mysql_query("delete from table where kw='$removeid'");

    }

  }

 

 

Thanks again. Mike

foreach() needs an array as the first argument and yours is a string. If u want to pass all or at least one post value to your array:

 

<?php
$id[] = $_POST['kwcb'];
?>

 

or

 

<?php
foreach($_POST as $val){
   $id[] = $val;
}
?>

Thanks, I got rid of the error, but only 1 result of the multiple checkboxes will delete. It doesn't loop through the rest of them.

 

This is my code:

 

	elseif ($action=='postdelete'){
	  $id = array();
	  $id[] = $_POST['kwcb'];

	  if (count($id) > 0)
	  {
	     foreach ($id as $removeid)
	     {
	      mysql_query("delete from table where kw='$removeid'");
	     }
	  }
}

If i get this right, u need to see which checkbox is checked and delete the related data. Then u need to have checkboxes with names like:

 

<input type="checkbox" name="checkbox[]" value="1" />

<input type="checkbox" name="checkbox[]" value="2" />

 

Note the square paranthesis in the checkbox name, which makes them an array. To get the values:

 

<?php
$id = array();
$id = $_POST['checkbox']; //u pass all the array data of the checkboxes to $id
foreach($id as $removeid){
    $mysql_query("DELETE FROM table WHERE kw='$removeid'");
}
?>

 

Hope its what u need.

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.