lovephp Posted November 17, 2012 Share Posted November 17, 2012 guys im trying to add up a action to delete all table if needed else delete row according to id. i added if($act==del){ mysql_query("DROP TABLE survey") or die(mysql_error()); } this should execute only if i make the url like del.php?act=del else only the DELETE FROM survey WHERE id = '$id' should work. tell me if its the right way <?php $id =$_REQUEST['id']; $user = $login->username; if($user =='administrator'){ // sending query mysql_query("DELETE FROM survey WHERE id = '$id'") or die(mysql_error()); header("Location: status.php"); }else{ header("Location: logout.php"); } if($act==del){ mysql_query("DROP TABLE survey") or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/ Share on other sites More sharing options...
AyKay47 Posted November 17, 2012 Share Posted November 17, 2012 1. Check that $_REQUEST['id'] is set and is an integer before using it, right now your code is open to SQL injection. 2. Where is $act coming from? 3. del is assumed to be a constant value without the value wrapped in quotes. Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393196 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2012 Share Posted November 17, 2012 Why do you need to dynamically drop a table? Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393197 Share on other sites More sharing options...
PFMaBiSmAd Posted November 17, 2012 Share Posted November 17, 2012 ^^^ Especially since your user level check code lets the rest of the code on your page run and anyone could drop the table. Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393199 Share on other sites More sharing options...
lovephp Posted November 17, 2012 Author Share Posted November 17, 2012 im tryin to make it available for me to drop all table if needed without deing the user=administrator but it does not seem to work and the $act=del i want to manually add it on url Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393200 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2012 Share Posted November 17, 2012 If you need to drop tables dynamically, chances are your database structure is wrong. Even so, trying to allow it without being logged in as administrator is dangerous. Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393201 Share on other sites More sharing options...
lovephp Posted November 17, 2012 Author Share Posted November 17, 2012 yes you are right i better drp this idea, thanks all Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393204 Share on other sites More sharing options...
PFMaBiSmAd Posted November 17, 2012 Share Posted November 17, 2012 lol, drop this idea, very punny. Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393207 Share on other sites More sharing options...
AyKay47 Posted November 17, 2012 Share Posted November 17, 2012 Please mark this as solved. Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393271 Share on other sites More sharing options...
lovephp Posted November 17, 2012 Author Share Posted November 17, 2012 done. Quote Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393273 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.