zeeshan Posted March 15, 2008 Share Posted March 15, 2008 hi this is an register.php when i uploaded it and when i opended the link thats not working i mean its invisible. <?phprequire_once 'db.php';$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';$error_string = '';if ($page_mode == 'register'){ $email = trim($_POST['email']); $name = trim($_POST['name']); $password = $_POST['password']; $conf_password = $_POST['conf_password']; if (!isValidEmail($email)) $error_string .= 'Please enter a valid email address.<br>'; if ($username == '') $error_string .= 'Please enter your username.<br>'; if (strlen(trim($password)) < 6) $error_string .= 'You must enter a password of at least 6 characters.<br>'; if ($password != $conf_password) $error_string .= 'The password and confirmation password do not match.<br>'; if ($error_string == '') { $result = db_query("SELECT id FROM info WHERE email='" . mysql_real_escape_string($email) . "'"); if (mysql_num_rows($result) > 0) $error_string .= 'That email address is already registerd.<br>'; else { $email = mysql_real_escape_string($email); $name = mysql_real_escape_string($name); $password = sha1($password); db_query("INSERT INTO info (email, username, password) VALUES ('{$email}', '{$username}', '{$password}')"); header('Location: thankyou.php'); exit(); } }}function isValidEmail($email = ''){ return preg_match("/^[\d\w\/+!=#|$?%{^&}*`'~-][\d\w\/\.+!=#|$?%{^&}*`'~-]*@[A-Z0-9][A-Z0-9.-]{1,61}[A-Z0-9]\.[A-Z]{2,6}$/ix",$email);}?><!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">Email address</div> <div class="right_box"><input type="text" name="email" size="30" maxlength="255" value="<?php if (isset($email)) echo $email; ?>"></div> <div class="left_box">username</div> <div class="right_box"><input type="text" name="username" size="30" maxlength="255" value="<?php if (isset($name)) 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 March 15, 2008 Share Posted March 15, 2008 ? That doesn't make sense you should have seen at least something. Link? Link to comment Share on other sites More sharing options...
zeeshan Posted March 15, 2008 Author Share Posted March 15, 2008 i forgot to add ?> but now the problem is when i enter the username an error is comming saying please enter ur username Link to comment Share on other sites More sharing options...
Synook Posted March 15, 2008 Share Posted March 15, 2008 I think you meant to write on line 12 if ($name == '') $error_string .= 'Please enter your username.<br>'; Link to comment Share on other sites More sharing options...
zeeshan Posted March 15, 2008 Author Share Posted March 15, 2008 yes so whats the error Link to comment Share on other sites More sharing options...
Synook Posted March 15, 2008 Share Posted March 15, 2008 You had a field named 'name' and so called your variable $name, but then tried to check $username (which didn't exist). Link to comment Share on other sites More sharing options...
zeeshan Posted March 15, 2008 Author Share Posted March 15, 2008 okthanx if i make $name into $username then will it work.edit:-when i entered my username after editing the script then it did not show the previous error but now its showing this errorWarning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/t/u/t/tutkings/htdocs/db.php:13) in /www/zxq.net/t/u/t/tutkings/htdocs/register.php on line 37 Link to comment Share on other sites More sharing options...
Synook Posted March 15, 2008 Share Posted March 15, 2008 You output something in db.php, post that code here. Link to comment Share on other sites More sharing options...
zeeshan Posted March 15, 2008 Author Share Posted March 15, 2008 ok <?php$con = mysql_connect('localhost', 'tutkings_zxq_net_z', 'computer');mysql_select_db('tutkings_zxq_net_info', $con);function db_query($sql){ return mysql_query($sql, $GLOBALS['con']);}?> and the information is being added to the db even after the error Link to comment Share on other sites More sharing options...
justsomeguy Posted March 15, 2008 Share Posted March 15, 2008 It is saying there is a problem on db.php line 13. Make sure that there are no spaces or blank lines after the ?> tag in that file, those will cause a problem. Link to comment Share on other sites More sharing options...
Synook Posted March 16, 2008 Share Posted March 16, 2008 By the way the headers already sent "error" is only a warning, which means code execution will continue anyway, you'll just see the warning on the screen (and that line would not work). Link to comment Share on other sites More sharing options...
zeeshan Posted March 16, 2008 Author Share Posted March 16, 2008 yes the code is working even after the warning but i dont want to show that error message and the username is not getting stored Link to comment Share on other sites More sharing options...
Synook Posted March 16, 2008 Share Posted March 16, 2008 i dont want to show that error messageWell stop the output in db.phpthe username is not getting storedDid you change $name = trim($_POST['name']); to $username = trim($_POST['name']); ? Link to comment Share on other sites More sharing options...
zeeshan Posted March 16, 2008 Author Share Posted March 16, 2008 yes Link to comment Share on other sites More sharing options...
Synook Posted March 17, 2008 Share Posted March 17, 2008 Do you have a field with name="name" on your form? If the field is named "username" then the line needs to be like $username = trim($_POST['username']); Link to comment Share on other sites More sharing options...
zeeshan Posted March 17, 2008 Author Share Posted March 17, 2008 yes i made it long ago Link to comment Share on other sites More sharing options...
justsomeguy Posted March 17, 2008 Share Posted March 17, 2008 And are you still getting any errors? If so, what are they? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.