ChidoriSoul Posted May 25, 2009 Share Posted May 25, 2009 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 More sharing options...
justsomeguy Posted May 26, 2009 Share Posted May 26, 2009 http://w3schools.invisionzone.com/index.php?showtopic=12509 Link to comment Share on other sites More sharing options...
ChidoriSoul Posted May 26, 2009 Author Share Posted May 26, 2009 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 More sharing options...
justsomeguy Posted May 27, 2009 Share Posted May 27, 2009 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 More sharing options...
ChidoriSoul Posted May 27, 2009 Author Share Posted May 27, 2009 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 More sharing options...
justsomeguy Posted May 27, 2009 Share Posted May 27, 2009 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 More sharing options...
ChidoriSoul Posted May 27, 2009 Author Share Posted May 27, 2009 well, ok, thanks, now just a question, is that correctly filled out, or is there a peice that I am missing, like where to fill in the port, etc. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 27, 2009 Share Posted May 27, 2009 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 More sharing options...
ChidoriSoul Posted May 27, 2009 Author Share Posted May 27, 2009 ('localhost', 'sa', ''); This part. Is this what you meant by localhost and everything else, if it is, then I did not fill it in Link to comment Share on other sites More sharing options...
justsomeguy Posted May 27, 2009 Share Posted May 27, 2009 $con = mysql_connect('host name', 'username', 'password');mysql_select_db('database name', $con); Link to comment Share on other sites More sharing options...
ChidoriSoul Posted May 27, 2009 Author Share Posted May 27, 2009 is the $con just there, or am I supposed to put something there? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 27, 2009 Share Posted May 27, 2009 That's a variable name, leave that as it is. Link to comment Share on other sites More sharing options...
ChidoriSoul Posted May 27, 2009 Author Share Posted May 27, 2009 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 More sharing options...
justsomeguy Posted May 27, 2009 Share Posted May 27, 2009 That doesn't select a table, it selects the database to use for the connection. You specify the table names in the individual SQL statements after the connection is made. Link to comment Share on other sites More sharing options...
ChidoriSoul Posted May 27, 2009 Author Share Posted May 27, 2009 Ah, ok, now just ot fill in the rest of the infos Link to comment Share on other sites More sharing options...
ChidoriSoul Posted May 28, 2009 Author Share Posted May 28, 2009 Wow, I just did the dumbest thing, I forgot to put the ' ' Now, Thanks, I got it connected Link to comment Share on other sites More sharing options...
ChidoriSoul Posted May 28, 2009 Author Share Posted May 28, 2009 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 More sharing options...
justsomeguy Posted May 28, 2009 Share Posted May 28, 2009 The db.php file was the file that contains the database connection code that you pasted near the top. It just needs to be saved in the same directory as the script trying to include it. Link to comment Share on other sites More sharing options...
ChidoriSoul Posted May 28, 2009 Author Share Posted May 28, 2009 Oh, ok, thanks Link to comment Share on other sites More sharing options...
ChidoriSoul Posted May 28, 2009 Author Share Posted May 28, 2009 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 More sharing options...
justsomeguy Posted May 28, 2009 Share Posted May 28, 2009 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 More sharing options...
ChidoriSoul Posted May 28, 2009 Author Share Posted May 28, 2009 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 More sharing options...
justsomeguy Posted May 28, 2009 Share Posted May 28, 2009 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 More sharing options...
ChidoriSoul Posted May 29, 2009 Author Share Posted May 29, 2009 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 More sharing options...
justsomeguy Posted May 29, 2009 Share Posted May 29, 2009 Blank lines count as output, make sure there are no blank lines before the beginning PHP tag. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.