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 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. 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 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! 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. 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 :/ 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. 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? 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? 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. 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. 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... 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 :-) 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... 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. Link to comment https://forums.phpfreaks.com/topic/242234-if-elseif-and-else/#findComment-1244146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.