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()); } ?> 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. 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? 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. 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 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. 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 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. 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. 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. Link to comment https://forums.phpfreaks.com/topic/270831-is-this-right-actdel/#findComment-1393273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.