Forum Moderators: coopster

Message Too Old, No Replies

Delete through a form

obtain no results!

         

henry0

3:06 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I pass start_date and end_ date and sectionID though a form
#####
<form action ="select.php" method="post">
Enter date_start:<input type="text"name="date_start" value="<?php echo $date_start;?>">
<p>
Enter date_end:<input type="text"name="date_end" value="<?php echo $date_end;?>">
<p>
Enter section_id:<input type="text"name="section_id" value="<?php echo $section_id;?>">
<p>

<br>
<input type="submit"></form>
####

that feeds the following query
####
<?
include("dbinfo_fortest.inc.php");//db conn script
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="delete * FROM articles_trial where adate between '$date_start' and '$date_end' and sectionID='$section_id'";

mysql_close();
?>

####

It has no effect on my db trial

do you see any wrong doing
thank you

regards

coopster

3:37 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You seem to prep everything, but did you actually execute the query? Then process any found $rows?
<?
include("dbinfo_fortest.inc.php");//db conn script
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="delete * FROM articles_trial where adate between '$date_start' and '$date_end' and sectionID='$section_id'";

[b]while ($row = mysql_query($query)) {
// processing here
}[/b]

mysql_close();
?>

Also, I'm not sure, but I never use the asterisk (*) in my DELETE statements:
DELETE FROM articles_trial...

Lastly, I recommend using an exit($query); right after building the $query variable just to double check your statement. You usually find your answer to unexpected query results (or lack thereof) this way quite quickly.

henry0

4:54 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thank you
indeed you are correct I forgot the row section!

now something else is happening
It works fine in selectively deleting the chosen rows

however the file is hanging forever
and the process bar shows progress but stays at about half way through
although the job is done

any idea?

coopster

5:20 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



however the file is hanging forever
and the process bar shows progress but stays at about half way through
although the job is done

You'll have to be a bit more specific. Which file is 'hanging forever' and what exactly do you mean by that?

RonPK

5:21 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no need for the while-loop. Just execute the query, once.

henry0

6:22 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



well if I remove the loop

nothing is happening

I really do not figure what is the problem here?
regards

henry0

6:38 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I came with a more ellaborate solution that works

<<<<
<?

function db_connect()
{
$result = @mysql_pconnect("aaaaaaa", "bbbbbb", "ccccccc");
if (!$result)
return false;
if (!@mysql_select_db("dddddddd"))
return false;

return $result;
}
?>

<?php
$conn = db_connect();
?>

<?php

$query="delete FROM articles_trial where adate between '$date_start' and '$date_end' and sectionID='$section_id'";
$result= mysql_query ($query);

?>

thank you

coopster

6:55 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



My apologies, a while statement should not have been used here. Only for SELECT, SHOW, EXPLAIN or DESCRIBE statements mysql_query() returns a resource identifier or FALSE if the query was not executed correctly. For other type of SQL statements, mysql_query() returns TRUE on success and FALSE on error, including the DELETE statement. Thanks, RonPK for catching that.

henry0

7:41 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Coopster we all do mistakes, thanks, but no need for apologies :)

Henry

coopster

7:51 pm on Aug 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yeah, I know we all make mistakes, but for me it's not very often (he said, tongue-in-cheek ;)), and especially in public -- a lesson in humbleness today, isn't life grand. Anyway, enought of my hot air! I just wanted to make sure that future readers of this post (today, tomorrow, next year, etc.) understood why the loop occurred. It's nice to see the fix, it's nicer to know the gory details -- makes us all well-informed, better, stronger, leaner, faster programmers. Thanks for the kind words henry0!