Akenatehm Posted November 24, 2008 Share Posted November 24, 2008 Hey Guys, I need to reverse this script so that it has the opposite effect and deletes the user instead of adding them. I need it to be able to search through the database when you input either of the fields (username, email etc.) or all of them etc. Help would be greatly appreciated. Here is my code: <?php include "../connect.php"; if(isset($_POST['submit'])) { $username=$_POST['username']; $password=$_POST['password']; $email=$_POST['email']; if(strlen($username)<1) { print "You did not enter a username."; } else if(strlen($password)<1) { print "You did not enter a password."; } else { $insert="Insert into users (username,pass,email) values('$username','$password','$email')"; mysql_query($insert) or die("Could not insert comment" . mysql_error()); print "User Added. <A href''<a href="home.html">Click here</a> To Go Home."; } } ?> Thanks in Advanced Akenatehm Link to comment https://forums.phpfreaks.com/topic/133992-deleting-from-mysql-database-using-php/ Share on other sites More sharing options...
Mchl Posted November 24, 2008 Share Posted November 24, 2008 And what problems do you have with doing it? Link to comment https://forums.phpfreaks.com/topic/133992-deleting-from-mysql-database-using-php/#findComment-697463 Share on other sites More sharing options...
Akenatehm Posted November 24, 2008 Author Share Posted November 24, 2008 I am completely unsure of how to do this. As far as I know it would involve delete from somewhere but I am not sure how I would go about this whole thing. Link to comment https://forums.phpfreaks.com/topic/133992-deleting-from-mysql-database-using-php/#findComment-697465 Share on other sites More sharing options...
Mchl Posted November 24, 2008 Share Posted November 24, 2008 Yes. The query would look like DELETE FROM users WHERE username = $username OR email = $email I think it won't be difficult for you to modify the code now. Link to comment https://forums.phpfreaks.com/topic/133992-deleting-from-mysql-database-using-php/#findComment-697466 Share on other sites More sharing options...
Akenatehm Posted November 24, 2008 Author Share Posted November 24, 2008 Thanks. Link to comment https://forums.phpfreaks.com/topic/133992-deleting-from-mysql-database-using-php/#findComment-697467 Share on other sites More sharing options...
Mchl Posted November 24, 2008 Share Posted November 24, 2008 Be careful. It will not ask you for any confirmation. And you should also protect yourself against SQL injecitons. Just think what happens if someone enters username to be deleted as this: $username = "'a' OR 1=1 " (the query would look like this DELETE FROM users WHERE username = 'a' OR 1=1 OR email = $email which would delete all users) Link to comment https://forums.phpfreaks.com/topic/133992-deleting-from-mysql-database-using-php/#findComment-697472 Share on other sites More sharing options...
Akenatehm Posted November 25, 2008 Author Share Posted November 25, 2008 I am not very sure about what this script is doing. I understand that $username is the variable but I am not unsure about what the 'a' is, is it the id of the html form? and the 1=1, I am also unsure of that. $username = "'a' OR 1=1 " Link to comment https://forums.phpfreaks.com/topic/133992-deleting-from-mysql-database-using-php/#findComment-698350 Share on other sites More sharing options...
peranha Posted November 25, 2008 Share Posted November 25, 2008 I am not very sure about what this script is doing. I understand that $username is the variable but I am not unsure about what the 'a' is, is it the id of the html form? and the 1=1, I am also unsure of that. $username = "'a' OR 1=1 " the "'a' OR 1=1 " is a sort of hack, if you dont clean your variables before you use them, people can get all sorts of information from your database, in this case, they would delete all your data. Look up "SQL injections" in google, and it will tell you about it. Link to comment https://forums.phpfreaks.com/topic/133992-deleting-from-mysql-database-using-php/#findComment-698352 Share on other sites More sharing options...
Akenatehm Posted November 25, 2008 Author Share Posted November 25, 2008 Thanks for that. I had a look and I understand it now. Much appreciated. Link to comment https://forums.phpfreaks.com/topic/133992-deleting-from-mysql-database-using-php/#findComment-698383 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.