I am trying to make a simple database delete script.

Im fairly new to php and mysql.

I need to access 3 tables in the database to delete all the relevany information for one user.

The articles, penname and users tables.

I adapted the code from a search script I put together.

The following code seems to work if the user has a penname and some articles, however doesnt seem to work if the user has no pennames or articles.

I probably need some if statements.

Thanks for any help.

This is the code:

<form name="search" method="post" action="<?=$PHP_SELF?>">
Search for: <input type="text" name="find" /> in 
<Select NAME="field">
<Option VALUE="email">Email Address</option>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />

//This is only displayed if they have submitted the form 
if ($searching =="yes") 
echo "<h2>Results</h2><p>"; 
//If they did not enter a search term we give them an error 
if ($find == "") 
echo "<p>You forgot to enter a search term"; 
// Otherwise we connect to our Database 
@mysql_connect($dbhost,$dbuser,$dbpasswd)or die("Connect Error: ".mysql_error());
mysql_select_db($dbname) or die( "Unable to select database");
// We preform a bit of filtering 
$find = strtoupper($find); 
$find = strip_tags($find); 
$find = trim ($find); 
//Now we search for our search term, in the field the user specified 
// Construct our join query
$data = mysql_query("DELETE articles, penname, users ".
 "FROM articles, penname, users ".
 "WHERE articles.penname_id = penname.user_id AND penname.user_id = users.user_id AND upper($field) ='$find'"); 
if ($anymatches == 0) 
echo "Sorry, but we can not find an entry to match your query<br><br>"; 
//And we remind them what they searched for 
echo "<b>The Records You Searched For:</b> " .$find; 
11 Years
Discussion Span
Last Post by phper

It's not working because the query is requiring the data to be present in each table.

You're going to need separate queries for each table.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.