/    Sign up×
Community /Pin to ProfileBookmark

Run different code if a field is blank

Hello there!
I need some help on a script. I have a form with that edits a row in the database, a form that have a browse button for images. What i need is to run a code if the field LajmeImg is not blank and anothe code if is blank.

I have used this 2 ways:

1.

[code=php]if(empty($_FILES[‘LajmeImg’]) && ($error == ”)) {

$sql = “UPDATE lajme SET KatLajmeID = ‘$KatLajmeID’, LajmeEmri = ‘$LajmeEmri’, LajmeLink = ‘$LajmeLink’, LajmeIntro = ‘$LajmeIntro’, LajmeTxt = ‘$LajmeTxt’, LajmeVideo = ‘$LajmeVideo’, LajmeTag = ‘$LajmeTag’, LajmeAktiv = ‘$LajmeAktiv’ WHERE LajmeID = ‘$LajmeID'”;

$query = mysql_query($sql) or die(“Fatal error: “.mysql_error());

}

else if (!empty($_FILES[‘LajmeImg’]) && ($error == ”)) {

$sql = “UPDATE lajme SET KatLajmeID = ‘$KatLajmeID’, LajmeEmri = ‘$LajmeEmri’, LajmeLink = ‘$LajmeLink’, LajmeIntro = ‘$LajmeIntro’, LajmeTxt = ‘$LajmeTxt’, LajmeVideo = ‘$LajmeVideo’, LajmeTag = ‘$LajmeTag’, LajmeImg = ‘$LajmeImg’, LajmeAktiv = ‘$LajmeAktiv’ WHERE LajmeID = ‘$LajmeID'”;

$query = mysql_query($sql) or die(“Fatal error: “.mysql_error());
[/code]

2.

[code=php]if(($LajmeImg == ”) && ($error == ”)) {

$sql = “UPDATE lajme SET KatLajmeID = ‘$KatLajmeID’, LajmeEmri = ‘$LajmeEmri’, LajmeLink = ‘$LajmeLink’, LajmeIntro = ‘$LajmeIntro’, LajmeTxt = ‘$LajmeTxt’, LajmeVideo = ‘$LajmeVideo’, LajmeTag = ‘$LajmeTag’, LajmeAktiv = ‘$LajmeAktiv’ WHERE LajmeID = ‘$LajmeID'”;

$query = mysql_query($sql) or die(“Fatal error: “.mysql_error());

}

else if (($LajmeImg !== ”) && ($error == ”)) {

$sql = “UPDATE lajme SET KatLajmeID = ‘$KatLajmeID’, LajmeEmri = ‘$LajmeEmri’, LajmeLink = ‘$LajmeLink’, LajmeIntro = ‘$LajmeIntro’, LajmeTxt = ‘$LajmeTxt’, LajmeVideo = ‘$LajmeVideo’, LajmeTag = ‘$LajmeTag’, LajmeImg = ‘$LajmeImg’, LajmeAktiv = ‘$LajmeAktiv’ WHERE LajmeID = ‘$LajmeID'”;

$query = mysql_query($sql) or die(“Fatal error: “.mysql_error());
[/code]

but, in both of them, when the field is empty didn’t let the “LajmeImg” DB field out of the query but updates the database with a value that i don;t know where it gets that and have only the name of the image existent on the DB without extension (ex: if the existent image name is [B]imagename.jpg[/B] now it looks like [B]imagename.[/B]). I supose that this mean that “if” statement didn;t worked correctly.

Hope that someone will help me on this. Thank you!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindOct 10.2010 — Where and How (and with what) is $LajmeImg being set?

When you're running your query, are you sure $LajmeImg is what you are expecting it to be? Have you output the query to see what it looks like?
×

Success!

Help @Kleidi 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.16,
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,
)...