Jump to content

Db.php File


e4games

Recommended Posts

<?phprequire_once 'db.php';$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';$error_string = '';if ($page_mode == 'register'){  $username = trim($_POST['username']); // trim to remove whitespace  $password = $_POST['password'];  $conf_password = $_POST['conf_password'];  if ($error_string == '')  {	$result = db_query("SELECT id FROM users WHERE username='" . mysql_real_escape_string($username) . "'");	if (mysql_num_rows($result) > 0)	  $error_string .= 'That username is already registerd.<br>';	else	{	  $username = mysql_real_escape_string($username); // protect against SQL attacks	  $password = sha1($password); // hash password	 db_query("INSERT INTO users (username, password) VALUES ('{$username}', '.sha1{$password}')");	  header('Location: thankyou.php');	  exit();	}  }}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>  <head>	<title>Register</title>	<style type="text/css">	.error_text {	  color: #FF0000;	  width: 400px;	  text-align: center;	}	.left_box {	  float: left;	  width: 150px;	  text-align: right;	  padding-right: 5px;	}	.right_box {	  clear: right;	}	</style>  </head>  <body>	<div class="error_text"><?php echo $error_string; ?></div>	<form action="register.php" method="post">	<input type="hidden" name="page_mode" value="register">	<div class="left_box">Username</div>	<div class="right_box"><input type="text" name="username" size="30" maxlength="255" value="<?php if (isset($username)) echo $username; ?>"></div>	<div class="left_box">Password</div>	<div class="right_box"><input type="password" name="password" size="30"></div>	<div class="left_box">Confirm Password</div>	<div class="right_box"><input type="password" name="conf_password" size="30"></div>	<div class="left_box"> </div>	<div class="right_box"><input type="submit" value="Register" size="30"></div>	</form>  </body></html>

Link to comment
Share on other sites

Make sure there aren't any mysql errors - disable the redirection and print out mysql_error().

Link to comment
Share on other sites

First, you have an extra comma here:mysql_select_db('Database_Name',);That's an error, if that's not printing an error message it should be, if you're not seeing a message that means they are disabled. Other than that, add error printing to the connect functions, that should be there. I'll update the post that came from to add error checking.$con = mysql_connect('FTP_Hostname', 'username', 'password') or exit(mysql_error());mysql_select_db('Database_Name') or exit(mysql_error());There might be an issue with the hostname, it might say it can't connect. If you're running this script on your web server you can probably just use "localhost" for the hostname, unless your host gave you a specific hostname to use for the database.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...