Trouble with form to delete database entries

I am trying to make a very basic form that will delete information from a database if the info put into the form matches the info in the database.

I have four columns in my database and four boxes on the HTML form into which I can type data. I would like it to work so if I put info into any of the boxes and that info matches any entry in the box’s corresponding database column, it will delete that entry, regardless of whether any info has been entered into the other boxes.

However my code either doesn’t delete anything at all, or it only pays attention to the first ‘if’ in my ‘if/else’ statement, and when info is entered into any box other than the first one on the HTML form, nothing gets deleted.

I am super beginner at this, I have no idea about what I’m doing, so any help is really appreciated!

[code]<?php
$server = ‘’;
$user = ‘’;
$pass = ‘’;
$db = ‘’;

// Connect to Database
$con = mysql_connect($server, $user, $pass)
or die (“Could not connect to server … \n” . mysql_error ());
mysql_select_db($db)
or die (“Could not connect to database … \n” . mysql_error ());

$a = $_POST[‘a’];
$b = $_POST[‘b’];
$c = $_POST[‘c’];
$d = $_POST[‘d’];

$arow = mysql_query(“SELECT column, a FROM table”);
$brow = mysql_query(“SELECT column, b FROM table”);
$crow = mysql_query(“SELECT column, c FROM table”);
$drow = mysql_query(“SELECT column, d FROM table”);

if($a==$arow)
{
$sql=“DELETE FROM table WHERE a == ‘$a’”;
mysql_query($sql) or die(mysql_error());
echo “deleted”;
}
elseif($b==$brow)
{
$sql2=“DELETE FROM table WHERE b == ‘$b’”;
mysql_query($sql2) or die(mysql_error());
echo “deleted2”;
}
elseif($c==$crow)
{
$sql3=“DELETE FROM table WHERE c == ‘$c’”;
mysql_query($sql3) or die(mysql_error());
echo “deleted3”;
}
elseif($d==$drow)
{
$sql4=“DELETE FROM table WHERE d == ‘$d’”;
mysql_query($sql4) or die(mysql_error());
echo “deleted4”;
}
else
{
echo “fail”;
}

mysql_close($con);
?>[/code]

you can do all that in 1 query using OR clauses, then if you dont want to match the physical value, you can see if any results are found with mysql_num_rows (). also, in the the delete query, its just 1 equal sign.

Sponsor our Newsletter | Privacy Policy | Terms of Service