/    Sign up×
Community /Pin to ProfileBookmark

execute code in or die

Can i execute some code in the or die of a query? I want to do this if the update of the db fail: setcookie (“Login”, “”, time() – 60*60);

Here is the update.
mysql_query($UpdateCookie,$db) or die(“Error:”.mysql_error());

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Apr 19.2004 — don't use die. Create a custom function and use that:

[code=php]
function halt($msg){
setcookie ("Login", "", time() - 60*60);
print $msg;
exit;
}


$result=@mysql_query($sql) or halt(mysql_error());
[/code]
Copy linkTweet thisAlerts:
@SamKookauthorApr 19.2004 — whe can put anything we want after the or... that's good to know.
Copy linkTweet thisAlerts:
@SamKookauthorApr 19.2004 — but can we put a or on every instruction like a setcookie?
Copy linkTweet thisAlerts:
@crh3675Apr 19.2004 — I don't see why not, just make sure to use the @ to supress errors before the command you are calling
Copy linkTweet thisAlerts:
@shimonApr 20.2004 — It's not necesarily bad style to do that, but it could lead to some pretty bad coding habits, especially if you suppress errors (which really is bad practice)

Hmm, but do make sure that you only use it with functions that do actually return false if they fail! so just make sure you think well about the logic of what you're doing and you'll be fine ?
×

Success!

Help @SamKook 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.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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