Jump to content

Register Script


ChidoriSoul

Recommended Posts

Hey, I am building a Register script, and I just Created the Table, now I am very lost on what to do o.o Just someone give me some examples or something to guide my way.Table

CREATE TABLE `Register` (  `ID` INT(11) NOT NULL AUTO_INCREMENT,   `Username` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,   `Pass` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,   `Email` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,   `Show Email` ENUM('Yes','No') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,   `Gender` ENUM('Male','Female','Private') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,   `Starter` ENUM('Bulbasaur','Charmander','Squirtle','Chikorita','Cyndaquil','Totodile','Treecko','Torchic','Mudkip','Turtwig','Chimchar','Piplup') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,  PRIMARY KEY (`ID`))TYPE = myisam;

Link to comment
Share on other sites

Yes, the thing is JSG, I am going to use that, just the thing is, how would I make that so it checks everything else, and it automatically updates the DB in the table, so it can store and keep the info, also, how do I connect the Database, is the code in there.

Link to comment
Share on other sites

I'm not sure where your problem is, the register example in the other thread shows fields for username, email, and password, and shows the form and processing code. You should be able to add more fields to the form and add similar PHP code to check whichever fields you want to check. That code doesn't only work with email, username, and password, those are just 3 random fields, you can use whatever other information you want. You just need to put it in the HTML form, get the value in the PHP script, and validate the value if it requires validation. To validate an enum field, for example, you would compare the submitted value with the possible enum values to make sure that the value is allowed.Yes, the database connection code is included in that thread, it's the very first piece of PHP in the register discussion.

Link to comment
Share on other sites

Well, I keep on getting the Error Messgae that it can't connect, is this correct?

<?php$con = mysql_connect('localhost', 'sa', ''); // fdb1.awardspace.com, chidorisoul_sh, ******mysql_select_db('w3', $con);function db_query($sql){  return mysql_query($sql, $GLOBALS['con']);}?>

Link to comment
Share on other sites

If it can't connect make sure the server, username, password, and database name are correct. If you're running this from a different server than the database is on, the database server will also need to be configured to allow remote connections. Many disable that for security.

Link to comment
Share on other sites

You have your information in the comment, I assume that when you run the script you replace the localhost etc with your info. If you need to specify a port you can do that in the host, it's only required if MySQL is listening on a non-standard port.

Link to comment
Share on other sites

so, the Host name is the DB Hostthen the DB name, well, for me, is the same as the DB User, now, does that link find the table in the Databaseand now, I have to figure out how to change the DB settings to Remote Connection

Link to comment
Share on other sites

Ok, so I just pasted what you have, and there is one thingWarning: require_once(db.php) [function.require-once]: failed to open stream: No such file or directory in /home/www/tparpg.awardspace.co.uk/register.php on line 17Fatal error: require_once() [function.require]: Failed opening required 'db.php' (include_path='.:/usr/local/php5/share/pear') in /home/www/tparpg.awardspace.co.uk/register.php on line 17What do I put for 'db.php'

Link to comment
Share on other sites

Ok, now that register is finished (or it should be), I need Login, and whenever I insert the code, it comes up with this:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/www/tparpg.awardspace.co.uk/login.php:3) in /home/www/tparpg.awardspace.co.uk/login.php on line 5Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/www/tparpg.awardspace.co.uk/login.php:3) in /home/www/tparpg.awardspace.co.uk/login.php on line 5

Link to comment
Share on other sites

There's a post about that error message in the same topic as the register code, it shows how to find the source of that error. Generally speaking, you've got some output happening on line 3 in login.php that is causing session_start to fail. You can't send any output before you use session_start, or any other function that sends a header.

Link to comment
Share on other sites

this is my first 5 lines

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">line 3<?phpline 5require_once 'db.php';

Link to comment
Share on other sites

Right, you're sending output before using session_start. That's the problem. Read that post that talks about that error, and check the PHP code in that thread to see how it's structured. Notice that I put the PHP code before the HTML code, it's like that for a reason.

Link to comment
Share on other sites

I sitll get the same errorWarning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/www/tparpg.awardspace.co.uk/login.php:3) in /home/www/tparpg.awardspace.co.uk/login.php on line 5Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/www/tparpg.awardspace.co.uk/login.php:3) in /home/www/tparpg.awardspace.co.uk/login.php on line 5

<?phpsession_start();require_once 'db.php';$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';$error_string = '';if ($page_mode == 'login'){  $email = $_POST['email'];  $password = $_POST['password'];  if (trim($email) == '' || trim($password) == '')    $error_string .= 'Please enter your email address and password.<br>';  else  {    $result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'");    if (!($row = mysql_fetch_assoc($result)))      $error_string .= 'The email address was not found.<br>';    elseif ($row['password'] != sha1($password))      $error_string .= 'The password did not match.<br>';    else    {      $_SESSION['user_id'] = $row['id'];      $_SESSION['user_name'] = $row['name'];      $_SESSION['user_email'] = $row['email'];      header('Location: index.php');      exit();    }  }}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...