/    Sign up×
Community /Pin to ProfileBookmark

is this Valid PHP statement

i have this code below that deletes rows that are out of date, but it keeps on deleting everything even if its not out of date.

[code=php]
$expiry = $ow[‘endtime’];
$now = time();

mysql_query(“DELETE FROM buildup WHERE $expiry<$now”);
[/code]

is the above valid and writen correctly.
becouse it deletes everything WHERE $expiry<$now musnt be working ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@felgallMay 26.2008 — It would depend on the value of $ow['endtime']. If that is in the wrong format for the comparison then you will get unexpected results.
Copy linkTweet thisAlerts:
@Design-is-BSMay 26.2008 — Is it supposed to be

[code=php]
$expiry = $now['endtime'];
$now = time();

mysql_query("DELETE FROM buildup WHERE $expiry<$now");
[/code]


(probably stupid question...)
Copy linkTweet thisAlerts:
@mitchellauthorMay 26.2008 — this is my full code any help will be good

[code=php]
<?php

require("connectdb.php");

echo "Updating........";

$query = mysql_query("SELECT * FROM buildings")
or die(mysql_error());

$result = mysql_fetch_array($query);
echo "<br>Connected to database";

$expiry = $result['endtime'];
$now = time();

while($row = mysql_fetch_array($query))
{
if($expiry<$now){
$buildingtype = $row['building'];

if($buildingtype == 1) {
$upgrade='bank';
} elseif($buildingtype == 2) {
$upgrade='townhall';
} elseif($buildingtype == 3) {
$upgrade='lab';
} elseif($buildingtype == 4) {
$upgrade='magic';
} elseif($buildingtype == 5) {
$upgrade='time';
} elseif($buildingtype == 6) {
$upgrade='image';
} elseif($buildingtype == 7) {
$upgrade='wall';
} elseif($buildingtype == 8) {
$upgrade='tower';
} else {
echo 'Error';
}
mysql_query("UPDATE users SET $upgrade=$upgrade+'1'");
echo "<br><br>Updated buildings Successfully";
echo "<br>Deleting Out of date logs.......";
mysql_query("DELETE FROM buildup WHERE $expiry<$now");
echo "<br>Deleted Expired Logs Successfully";
}

}
?>
[/code]


any reason why its deleting all results even though ive put WHERE $expiry<$now ?

the above should go through the table and get everything that has expired (IF $expiry<$now) and update and delete
×

Success!

Help @mitchell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...