manix Posted June 26, 2011 Share Posted June 26, 2011 Well I have this really simple registration form with only username and password and only 1 acc per IP <?php $ip = $_SERVER['REMOTE_ADDR']; $username = $_POST['username']; $pass = $_POST['pass']; include 'condb.php'; $query = "SELECT ip FROM users WHERE ip='$ip'"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ $msg="You have already registered an account from this IP"; $window="login.php"; goto end; } $query = "SELECT ip, username FROM users WHERE ip<>'$ip' AND username<>'$username'"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ mysql_query("INSERT INTO users (ip, username, password) VALUES('$ip', '$username', '$pass')"); $msg="You registered successfully!"; $window="login.php"; goto end; } mysql_close(); $window="register.php"; $msg= "This name is already taken!"; end: include $window; if (isset($msg)){echo "<br><br><div align='center'><table vspace='100' bgcolor='#ffffff' border='1' style='border: none' width='40%' heigth='20%'><tr><td><strong><div align='center'><font size='5' color='red'>$msg</font></div></strong></td></tr></table></div>";} ?> condb.php is set up correctly server error: Server error The website encountered an error while retrieving http://manix.freehosting.bg/sendaccinfo.php. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this web page later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. Reload doesn't fix the problem EDIT: This runs perfectly on my localhost, but on my shared hosting the error is what happens.. Quote Link to comment https://forums.phpfreaks.com/topic/240434-php-code-server-error/ Share on other sites More sharing options...
revraz Posted June 26, 2011 Share Posted June 26, 2011 What are you trying to accomplish here? $query = "SELECT ip, username FROM users WHERE ip<>'$ip' AND username<>'$username'";$result = mysql_query($query); while($row = mysql_fetch_assoc($result)){mysql_query("INSERT INTO users (ip, username, password) VALUES('$ip', '$username', '$pass')"); $msg="You registered successfully!"; $window="login.php"; Also, you should count rows that are returned and use IF statements instead of GOTOs, would much more standard. Quote Link to comment https://forums.phpfreaks.com/topic/240434-php-code-server-error/#findComment-1234956 Share on other sites More sharing options...
manix Posted June 26, 2011 Author Share Posted June 26, 2011 well I'm checking if the username and ip are not in the DB and then inserting the data, I will now try to do it with ifs and see if it works Quote Link to comment https://forums.phpfreaks.com/topic/240434-php-code-server-error/#findComment-1234959 Share on other sites More sharing options...
PFMaBiSmAd Posted June 26, 2011 Share Posted June 26, 2011 Does your web host have php5.3, so that the goto statement is available? A) Using 'newly' added php features is generally not a good idea unless you have control of the final server it will be used on. B) Using goto is also generally not a good idea. You should write simple conditional logic to accomplish what you are tying to do. C) Using goto to exit while loops is also not a good idea because you should not be using a while loop to test if there are any results from a query when you expect only zero or one result. D) Using a goto statement is never a good idea. E) Even php.net has a cartoon in the goto documentation making fun of using a goto statement. F) You get the idea. Quote Link to comment https://forums.phpfreaks.com/topic/240434-php-code-server-error/#findComment-1234960 Share on other sites More sharing options...
manix Posted June 26, 2011 Author Share Posted June 26, 2011 oh I see, I really learned from your post thank you! Here's my code (that works now) <?php $ip = $_POST['userip']; $username = $_POST['username']; $pass = $_POST['pass']; include 'condb.php'; $query = "SELECT ip, username FROM users"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ if ($row['ip']==$ip){ $msg="<font size='5' color='red'>You have already registered from this IP!"; $window="login.php"; }else{ if ($row['username']==$username){ $msg="<font size='5' color='red'>This name is taken"; $window="register.php"; }else{ $msg="<font size='5' color='green'>You registered successfully!!"; $window="login.php"; mysql_query("INSERT INTO users (ip, username, password) VALUES('$ip', '$username', '$pass')"); } } } mysql_close(); echo "<br><br><div align='center'><table vspace='100' bgcolor='#ffffff' border='1' style='border: none' width='40%' heigth='20%'><tr><td><strong><div align='center'>$msg</font></div></strong></td></tr></table></div>"; include $window; ?> But isn't that going to make it insert the data every time when ip<>$ip and username<>$username ? Quote Link to comment https://forums.phpfreaks.com/topic/240434-php-code-server-error/#findComment-1234962 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.