Jump to content

Php code > server error


manix

Recommended Posts

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

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.