Jump to content

[SOLVED] Novice SQL Error


Akenatehm

Recommended Posts

Hey guys, somethings wrong with this syntax, I was just trying and experimenting. I am sure it won't be something big thats wrong with it.

 

Here it is:

 

<?php

include "connect.php";

if(isset($_POST['submit']))

{
   $username=$_POST['username'];

   $email=$_POST['email'];

   if(strlen($username)<1)

   {

      print "You did not enter a username.";

   }

   else

   {

      $delete="DELETE FROM users WHERE username = '$username' OR 1=1 OR email = $email";

      mysql_query($delete) or die("Could not delete user" . mysql_error());
  
  echo "User Deleted. <A href''<a href=\"home.html\">Click here</a> To Go Home.";
   }

  }

?>

Link to comment
https://forums.phpfreaks.com/topic/134312-solved-novice-sql-error/
Share on other sites

DELETE FROM users WHERE username = '$username' OR 1=1 OR email = $email

^ deletes all users.....

 

use

DELETE FROM users WHERE username = '$username' OR email = '$email'

(also note the added quotes around the email)

 

and you should really cleanse input with mysql_real_escape_string() or something similar

It means if someone sneaks a "'" into your textbox, then they can write there own SQL query that could drop, delete, or read your database. Its called SQL Injection and you might want to make your scripts more secure before you get too far into your coding that it would take hours and many errors to get your code secure.

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.