DeltaW7 Posted October 15, 2008 Share Posted October 15, 2008 Hi, Could someone help me with this script I wrote please? The problem is, if you submit data from a form to the page, everything works up to the point of elseif ($user->loadalias($_POST['alias'])). I have tried commenting out all the lines below, but ever time the page is blank. No errors, warnings, nothing. Doe's that make sense? Thank you The Page ----------------------- <?php if ((!isset($_POST['email'])) || (strlen($_POST['name']) == 0) || (strlen($_POST['email']) == 0) || (strlen($_POST['alias']) == 0) || (strlen($_POST['password']) == 0) || (strlen($_POST['retype']) == 0)) { WriteForm("Please complete all fields."); } else { require_once("includes/user.class.php"); $user = new user(); if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { WriteForm("Invalid email address."); } elseif ($user->loademail($_POST['email'])) { WriteForm("Email address has already been registered."); } elseif ($user->loadalias($_POST['alias'])) { WriteForm("Alias has already been taken by another user."); } elseif (strlen($_POST['password']) < { WriteForm("Password must be at least 8 characters long."); } elseif ($_POST['password'] != $_POST['retype']) { WriteForm("Your passwords don't match."); } else { $user->name = $_POST['name']; $user->email = $_POST['email']; $user->setpassword($_POST['password']); $user->alias = $_POST['alias']; $user->save(); $_SESSION['user'] = $user; WriteForm("COMPLETE"); } } ?> The WriteForm method just has echo $message; Nothing else. ----------------- The user class <?php class user { public $id; public $name; public $email; public $alias; public $password; public $dob; public $locationid; protected $db; function user() { require_once("config.php"); require_once("db.class.php"); $this->db = new db(); } public function setpassword($password) { if (strlen($password) < { return false; } $this->password = md5($password); return true; } public function checkpassword($password) { if ($this->password == md5($password)) { return true; } return false; } public function loademail($email) { $this->db->connect(); $result = $this->db->queryone("SELECT * FROM users WHERE email='" . $email . "'"); if ($result) { $this->id = $result['id']; $this->name = $result['name']; $this->email = $result['email']; $this->alias = $result['alias']; $this->password = $result['password']; $this->dob = $result['dob']; $this->locationid = $result['locationid']; $this->db->disconnect(); return true; } $this->db->disconnect(); return false; } public function loadalias($alias) { $this->db->connect(); $result = $this->db->queryone("SELECT * FROM users WHERE alias='" . $alias . "'"); if ($result) { $this->id = $result['id']; $this->name = $result['name']; $this->email = $result['email']; $this->alias = $result['alias']; $this->password = $result['password']; $this->dob = $result['dob']; $this->locationid = $result['locationid']; $this->db->disconnect(); return true; } $this->db->disconnect(); return false; } public function save() { $this->db->connect(); if (isset($this->id)) $this->db->nonquery("UPDATE users SET email='" . $this->email . "', password='" . $this->password . "', name='" . $this->name . "', dob='" . $this->dob . "', alias='" . $this->alias . "', locationid='" . $this->locationid . "' WHERE id='" . $this->id . "'"); else $this->db->nonquery("INSERT INTO users VALUES ('', '" . $this->email . "','" . $this->password . "','" . $this->name . "','" . $this->dob . "','" . $this->alias . "','" . $this->locationid . "')"); $this->db->disconnect(); } public function delete() { $this->db->connect(); if (isset($this->id)) $this->db->nonquery("DELETE FROM users WHERE id='" . $this->id . "'"); $this->db->disconnect(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128507-could-someone-help-a-newbie-debug-this-script/ Share on other sites More sharing options...
gaza165 Posted October 15, 2008 Share Posted October 15, 2008 turn error reporting on at the top of your page place this code at the top of your page and see if it gives in errors.. error_reporting(E_ALL); Garry Quote Link to comment https://forums.phpfreaks.com/topic/128507-could-someone-help-a-newbie-debug-this-script/#findComment-665989 Share on other sites More sharing options...
DeltaW7 Posted October 15, 2008 Author Share Posted October 15, 2008 Hi, Thanks for the tip, I have done as you suggested and no errors where thrown. Here is the page: http://www.friendcodes.co.uk/register.php If you fill in fake data, everything works fine up to the point after the check is done to see if the user exists. I have a test user in the database email address bob@hope.com, his alias is Test User. I have been using it to check the form validation. Any other thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/128507-could-someone-help-a-newbie-debug-this-script/#findComment-666031 Share on other sites More sharing options...
revraz Posted October 15, 2008 Share Posted October 15, 2008 Turning on errors is the first step, but you also have to Display them. Quote Link to comment https://forums.phpfreaks.com/topic/128507-could-someone-help-a-newbie-debug-this-script/#findComment-666101 Share on other sites More sharing options...
DeltaW7 Posted October 15, 2008 Author Share Posted October 15, 2008 Hi, Give me a clue, newbie at work... Quote Link to comment https://forums.phpfreaks.com/topic/128507-could-someone-help-a-newbie-debug-this-script/#findComment-666108 Share on other sites More sharing options...
revraz Posted October 15, 2008 Share Posted October 15, 2008 ini_set("display_errors", 1); Quote Link to comment https://forums.phpfreaks.com/topic/128507-could-someone-help-a-newbie-debug-this-script/#findComment-666109 Share on other sites More sharing options...
Maq Posted October 15, 2008 Share Posted October 15, 2008 Put this at the top of your page: ini_set ("display_errors", "1"); error_reporting(E_ALL); You should also echo out all of your variables to make sure they have the correct values. Quote Link to comment https://forums.phpfreaks.com/topic/128507-could-someone-help-a-newbie-debug-this-script/#findComment-666115 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.