/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] IF Statement Problem

I am using IF statements in a part of a user editing script. This script draws user information from a database and allows you to edit it. My problem with this script is the password editing, I am using MD5 encrypting for this as it is the easiest to use, and I have it set not to show the password in the form for obvious security reasons. Now, when the page is submited, this information is sent over to another page which then submits this to a database. The Only problem was that when I checked the database to see if it had worked, I saw that the password was blank, because of course of the blank field. So I set up this IF statement….

[code=php]
if($edit_password == “”) {
$insertquery = “UPDATE users SET username = ‘$edit_username’, email = ‘$edit_email’, accesslvl = ‘$edit_accesslvl’ WHERE username = ‘$user'”;
} else {
$edit_password = md5($edit_password);
$insertquery = “UPDATE users SET username = ‘$edit_username’, password = ‘$edit_password’, email = ‘$edit_email’, accesslvl = ‘$edit_accesslvl’ WHERE username = ‘$user'”;
}
[/code]

….to check if the password field is empty, if it is, it doesn’t change the password field(there is a mysql_query that runs below with the value of the variable), but(else), If it has something in it it does edit the password. Only, I ran the code, and it still empty’s the password form, what is up with this? It confuses me as I was sure this would work.

to post a comment
PHP

20 Comments(s)

Copy linkTweet thisAlerts:
@cridleyJul 08.2006 — Are you using POST? then try

if(isset($_POST['edit_password']) && $_POST['edit_password'] == "")

and replace all occurences of $edit_password with $_POST['edit_password']

Also replace other posted vars with $_
POST['varname'].
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 08.2006 — Of course I am using that, I should'v explained, above that, I have set [code=php]$edit_password = $_POST['edit_password'];[/code] so that part of the code is perfectly ok
Copy linkTweet thisAlerts:
@cridleyJul 08.2006 — yes, but try this in a file on its own

if ($bob=="")

echo "bob";

this will display "bob". are you using isset($_POST['varname']) to check it exists?
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 08.2006 — Why would I need to echo bob, IF statements work for me normally, but today they are not, and no offense meant, but I was hoping for some help from NogDog or bokeh, or sheldon or someone like that who'v helped me before. They seem to help me more than anyone else. Again, no offense meant here, I just prefer there help.
Copy linkTweet thisAlerts:
@cridleyJul 08.2006 — wtf?
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 08.2006 — I said no offense, I just think nogdog could help me quicker is all. Sorry.
Copy linkTweet thisAlerts:
@NogDogJul 08.2006 — My suspicion is that you're picking up a space, newline, or some other white-space character in the supposedly empty variable, and therefore it is not equating to an empty string. Just for fun try chaning how you set it to this:
[code=php]
$edit_password = trim($_POST['edit_password']);
[/code]
Copy linkTweet thisAlerts:
@NogDogJul 08.2006 — PS: Everyone who registers here is free to try and help you. You have the perogative of ignoring their advice if you wish, but I'd prefer that you not discourage them simply for being willing to freely spend some of their own time trying to assist you.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 08.2006 — I know, I was out of line, I am sorry cridley. Like I previously said, I meant no offensive.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 08.2006 — Ok Nogdog, Thanks, It now does not edit it when I set it like you said.

[b]EDIT:[/b] Sorry for double post, I forgot to use EDIT button on above post
Copy linkTweet thisAlerts:
@cridleyJul 08.2006 — sorry, I overreacted but as I said, just trying to help. If i can't see the whole code then i have to make assumptions about what's missing.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 08.2006 — I would prefer not to give out my code for this though, it is rather long on this piticular part because of other features and such in it. So it would rather hard to read anyways. This is why I gave only the IF statement, and I just forgot to give the variable that I set along with it. Sorry again.
Copy linkTweet thisAlerts:
@sitehatcheryJul 09.2006 — users.password
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 09.2006 — I'm sorry, What?
Copy linkTweet thisAlerts:
@sitehatcheryJul 09.2006 — nm, looks like you marked it resolved.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 09.2006 — Yes, I did like three hours ago, but why did you say "users.password" that didn't make any since.
Copy linkTweet thisAlerts:
@sitehatcheryJul 09.2006 — I ran into an issue recently where I used the reserved word "order" and got similar results - I seemed to have everything right, but it would not right it to the database, and there were no errors. I thought I remember "password" being a reserved word (there are tons of them), but I double-checked and found that it was not a reserved word. So, that's not it. What'd you do to fix it?
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 09.2006 — O.o Ok, Parhaps Nogdog can explain what you just said to me sometime (brain hurting from learning to make OS). Anyways, I changed
[code=php]$edit_password = $_POST['edit_password'];[/code]
to
[code=php]$edit_password = trim($_POST['edit_password']);[/code]. It was counting "" as like a " " or something like Nogdog said here My suspicion is that you're picking up a space, newline, or some other white-space character in the supposedly empty variable, and therefore it is not equating to an empty string. Just for fun try chaning how you set it to this:
[code=php]
$edit_password = trim($_POST['edit_password']);[/code]
[/quote]
. Mabey you should'v read the intirety of the post ?. Anyways, Back to the learning pits for me.
Copy linkTweet thisAlerts:
@sitehatcheryJul 09.2006 — Like you, I want to learn. You never said what you did to fix it until I asked, but just marked it resolved. That doesn't do anybody any good.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorJul 09.2006 — actually, if you [b]had[/b] actually read the posts, you would'd seen that I did say what fixed it Ok Nogdog, Thanks, It now does not edit it when I set it like you said.[/quote] Now, lets break that one down, I thanked him, Next I explained.. ? could it be, what fixed it. wow. "It does not edit it, when I set it like you said". that explains it all, because when you look right above it. He told me to set something. So yes, you probobly should read the intirety of the posts more carefully.
×

Success!

Help @Heavy_Metal 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.28,
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,
)...