php - Delete multiple lines in MySQL from a string -



php - Delete multiple lines in MySQL from a string -

i know has been asked few times, i've looked through quite few posts , not find help me out.

i have javascript function add together values element appear such:

value="1,3,5,16"

however values different depending on user chooses. value sent php file perform mysql delete function database.

each value id number of record in database need deleted.

i cannot mysql statement recognize multiple id numbers. recognizes 1 (the first).

html:

<form method='post' action='delete_ids.php'> <input type='hidden' value="1,2,4,8,12,16" id='myvalues' name='myvalues'/> <button type='submit' id='submitbtn'>submit</button> </form>

php:

<?php require("config.php"); // database connection $x = $_post['myvalues']; $result = "delete `image_upload2` id in ('$x')"; $statement = $db->prepare($result); $count = $statement->execute(); ?>

it works fine if there 1 value, when there multiple values (commas in between) delete first record , not rest. in illustration above, 'id' = 1 deleted.

the single quotes around $x turn string literal (in context of sql statement sent database). example, consider:

delete foo bar in ('fee,fi,fo,fum');

the database doesn't care commas within string literal; database sees single string, 1 element within parens. comma characters part of string.

i think want comma interpreted part of sql syntax. want query of form:

delete `image_upload2` id in (1,2,4,8,12,16);

--or--

delete `image_upload2` id in ('1','2','4','8','12','16');

in examples, comma characters seen part of sql syntax, separating literals.

(and create brief mention here current code vulnerable sql injection, that's reply different question.)

xkcd exploits of mom

php mysql arrays string sql-delete

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -