mark103 Posted January 29, 2012 Share Posted January 29, 2012 Hi guys, I need a bit of your help. I have successfully deleted a row in a database after I have inserted the value name with a var function that match with a username in the url bar. Now I would like to delete more than one row, but I don't know how to do this? What I am trying to achieve is to enter the url something like this: www.mysite.com/delete.php?favorites=the value1&use=test It will search for a value in the database and then delete it. But if I add the &favorites=the value2 or more than 2, then search for the values in each row while looking for a username before delete the rows Here's the current code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $favorites = clean($_GET['favorites']); $username = clean($_GET['user']); if($favorites == '' && $username == ''){ // both are empty $errmsg_arr[] = 'Both name and email are missing. You must enter one or the other.'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['favorites'])) { $insert[] = 'favorites = \'' . clean($_GET['favorites']) . '\''; } if(($favorites) && isset($username)) { mysql_query("DELETE FROM favorites WHERE username='$username' AND favorites='$favorites'"); $deleted = mysql_affected_rows(); if($deleted > 0) { echo "favorites rows is deleted"; } else { echo("favorites are already deleted"); } } } ?> Any advice would be much appreciated. Thanks, Mark Quote Link to comment https://forums.phpfreaks.com/topic/256002-how-to-delete-more-than-one-database-row/ Share on other sites More sharing options...
spiderwell Posted January 29, 2012 Share Posted January 29, 2012 you would need to make each favorite have a unique name or they will overwrite, and I dont think you can pass an array as a querystring. so it would have to be favorite1=value&favorite2=value you can post arrays definately so maybe a post instead of a get? then at the posted script loop through the array do delete the items Quote Link to comment https://forums.phpfreaks.com/topic/256002-how-to-delete-more-than-one-database-row/#findComment-1312315 Share on other sites More sharing options...
scootstah Posted January 30, 2012 Share Posted January 30, 2012 and I dont think you can pass an array as a querystring. You can, the same way that you can with POST. The query string would look like example.com?favorite[]=1&favorite[]=2&favorite[]=3 Quote Link to comment https://forums.phpfreaks.com/topic/256002-how-to-delete-more-than-one-database-row/#findComment-1312384 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.