syco Posted May 11, 2008 Share Posted May 11, 2008 For some reason it says there is an invalid key or something... dusacomp.zxq.net/register.phptry and register and it says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/zxq.net/d/u/s/dusacomp/htdocs/register.php on line 28Warning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/d/u/s/dusacomp/htdocs/register.php:28) in /www/zxq.net/d/u/s/dusacomp/htdocs/register.php on line 37 <?phprequire_once 'db.php';$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';$error_string = '';if ($page_mode == 'register'){ $email = trim($_POST['email']); // trim to remove whitespace $name = trim($_POST['username']); // trim to remove whitespace $password = $_POST['password']; $conf_password = $_POST['conf_password']; if (!isValidEmail($email)) $error_string .= 'Please enter a valid email address.<br>'; if ($name == '') $error_string .= 'Please enter your name.<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 users 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); // protect against SQL attacks $name = mysql_real_escape_string($name); $password = sha1($password); // hash password db_query("INSERT INTO users (email, name, password) VALUES ('{$email}', '{$name}', '{$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 $name; ?>"></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...
justsomeguy Posted May 12, 2008 Share Posted May 12, 2008 There's an error with the SQL statement (where did you get "invalid key" from that?). You can add a line to print the SQL error if the query failed. $result = db_query("SELECT id FROM users WHERE email='" . mysql_real_escape_string($email) . "'");if (!$result) echo mysql_error(); Link to comment Share on other sites More sharing options...
syco Posted May 12, 2008 Author Share Posted May 12, 2008 actually my register works fine but i'll add that in thanks, i did post about my new problem http://w3schools.invisionzone.com/index.php?showtopic=19386 When your logged in its supposed to show the username on the homepage but it shows nothing...I did get this code from your code, and i changed all the $name, user_name to $username, user_username and in the table i changed name to username, so can you go there and help out?BTW i meant invalid code not key. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.