Jump to content

Deleting From MySQL Database Using PHP


Akenatehm

Recommended Posts

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

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)

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 " 

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.