e4games Posted September 19, 2009 Share Posted September 19, 2009 So I used the Database code that justsomeguy made and on my website, when you go to register it says that you did but then when I go to the database it says its empty. What's wrong and how should I fix it? Link to comment Share on other sites More sharing options...
boen_robot Posted September 19, 2009 Share Posted September 19, 2009 Do you have display_errors set to On? Any errors on screen? Link to comment Share on other sites More sharing options...
e4games Posted September 19, 2009 Author Share Posted September 19, 2009 Do you have display_errors set to On? Any errors on screen?I don't think so. All I have to do is this$error_string .= 'Error message here.'; Link to comment Share on other sites More sharing options...
Synook Posted September 20, 2009 Share Posted September 20, 2009 Which "Database code that justsomeguy made" is this? Link to comment Share on other sites More sharing options...
e4games Posted September 20, 2009 Author Share Posted September 20, 2009 <?php$con = mysql_connect('FTP_Hostname', 'username', 'password');mysql_select_db('Database_Name',);function db_query($sql){ return mysql_query($sql, $GLOBALS['con']);}?> Link to comment Share on other sites More sharing options...
Synook Posted September 21, 2009 Share Posted September 21, 2009 Ah, well, what is the rest of the register code? Link to comment Share on other sites More sharing options...
e4games Posted September 21, 2009 Author Share Posted September 21, 2009 <?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 More sharing options...
Synook Posted September 21, 2009 Share Posted September 21, 2009 Make sure there aren't any mysql errors - disable the redirection and print out mysql_error(). Link to comment Share on other sites More sharing options...
justsomeguy Posted September 23, 2009 Share Posted September 23, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.