Linjon Posted July 18, 2011 Share Posted July 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/ Share on other sites More sharing options...
teynon Posted July 18, 2011 Share Posted July 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1243950 Share on other sites More sharing options...
AyKay47 Posted July 18, 2011 Share Posted July 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1243966 Share on other sites More sharing options...
chintansshah Posted July 18, 2011 Share Posted July 18, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1243996 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1243998 Share on other sites More sharing options...
Linjon Posted July 18, 2011 Author Share Posted July 18, 2011 Thank's. By the way, how can i edit post ? Can't find "edit" button :/ Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244044 Share on other sites More sharing options...
chintansshah Posted July 18, 2011 Share Posted July 18, 2011 just create new post, don't be edit to older one. Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244047 Share on other sites More sharing options...
AyKay47 Posted July 18, 2011 Share Posted July 18, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244097 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 Where? In the code I wrote, no. Should there be? Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244104 Share on other sites More sharing options...
teynon Posted July 18, 2011 Share Posted July 18, 2011 ... 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. Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244106 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 There is no echo? Do you mean the die()? Im confused. Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244119 Share on other sites More sharing options...
AyKay47 Posted July 18, 2011 Share Posted July 18, 2011 what I meant is that you posted the exact same thing as I did... Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244126 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 Oh yeah, LOL sorry. Have been 10h at work now, starting to lose it. Didnt notice your post. You hide the link so well with url tags :-) Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244135 Share on other sites More sharing options...
AyKay47 Posted July 18, 2011 Share Posted July 18, 2011 lol...no problem, I found it more amusing at the fact that you thought that I meant the PHP function echo instead... Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244139 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 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(). Was few times like wtf^1000. People telling every second post there is a echo.. theres not echo!, thereeeeeeeis eccccccHOOOOOOOOO. Quote Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244146 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.