Jump to content

If, elseif and else


Linjon

Recommended Posts

Hello, i'm stuck with if, else if and else. My script doesn't work (no errors but doesn't work). I think problem is in this part:

 

//if username not found, insert that
if (!$row){ 
mysql_query("INSERT INTO `users` (username, password, access, created, expired, days) VALUES('$username', '$password', '$access', '$created', '$expires', '$days')");
echo $reply1;
}
//if user have same "access"
else if ($access == $accessCurrent){
mysql_query("UPDATE `users` (username, password, access, created, expired, days) VALUES('', '', '', '', '$expiresNew', '')");
echo $reply2;
}
//if user haves different "access"
else{
mysql_query("INSERT INTO `users_2` (username, password, access, created, expired, days) VALUES('$username', '$password', '$access', '$created', '$expires', '$days')");
mysql_query("UPDATE `users` (username, password, access, expired, days) VALUES('', '', '$accessNew', '')");
echo $reply3;
}

 

If you know what's wrong then tell me :P

Link to comment
Share on other sites

Your explanation of it doesn't work is pretty basic.

 

You probably don't have error reporting on.

 

Either way, you need to put some conditionals on the mysql_query statements. Quick way to determine what is happening, put or die(mysql_error()); on the end of each mysql query.

 

If you want a better response, post what is happening entirely and post all of your code.

Link to comment
Share on other sites

Hello,

 

I also believe that you have an error in mysql queries.

 

I am guessing that your

else{
mysql_query("INSERT INTO `users_2` (username, password, access, created, expired, days) VALUES('$username', '$password', '$access', '$created', '$expires', '$days')");

is wrong, please confirm that you have 'users_2' table is exist in to database!

Link to comment
Share on other sites

Your UPDATE query is not valid. Should be something like this

 

mysql_query("UPDATE `users` SET access = '$accessNew' WHERE username = '$username'") or die(mysql_error()); // More fields will be separated by comma.

 

See: http://dev.mysql.com/doc/refman/5.0/en/update.html . You would have also seen this if you used mysql_error() for debugging your queries like mentioned above.

Link to comment
Share on other sites

Thank's. By the way, how can i edit post ? Can't find "edit" button :/

You are only allowed to edit a post within 5-10 minutes of its creation ( not sure of the exact timeframe)

 

Your UPDATE query is not valid. Should be something like this

 

Code: [select]

mysql_query("UPDATE `users` SET access = '$accessNew' WHERE username = '$username'") or die(mysql_error()); // More fields will be separated by comma.

 

See: http://dev.mysql.com/doc/refman/5.0/en/update.html . You would have also seen this if you used mysql_error() for debugging your queries like mentioned above.

 

is there an echo in here?

Link to comment
Share on other sites

...

If you do what teynon suggested and use mysql_error, you will no doubt find the error(s) to occur in your mysql update statements. The syntax is all wrong.

 

For correct syntax, refer here

 

Your UPDATE query is not valid. Should be something like this

 

mysql_query("UPDATE `users` SET access = '$accessNew' WHERE username = '$username'") or die(mysql_error()); // More fields will be separated by comma.

 

See: http://dev.mysql.com/doc/refman/5.0/en/update.html . You would have also seen this if you used mysql_error() for debugging your queries like mentioned above.

 

I believe this is the echo in question.

Link to comment
Share on other sites

lol...no problem, I found it more amusing at the fact that you thought that I meant the PHP function echo instead...

 

Haha.. that is indeed what I was thinking all the time, a php echo().  :D Was few times like wtf^1000. People telling every second post there is a echo.. theres not echo!, thereeeeeeeis eccccccHOOOOOOOOO.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.