Jump to content

PHP & Mysql wierd problem


merlieon

Recommended Posts

Hello right now i'm kind of lost becuase i used db4free.net database and well it crashed but now its upp again on another server but the problem here is that the registration form wont send any data to the database but it worked on the crashed database (when it was up and running) so what could be the problem?

can't find the problem, i'm a little bit newbe in php (alot of code from tutorial)

//register.php
<?php
logged_in_redirect();
	if (empty($_POST) === false){
		$required_fields = array('username', 'password', 'password_again', 'email');
		foreach($_POST as $key=>$value){
			if (empty($value) && in_array($key, $required_fields) === true){
				$errors[] = 'fields marked with an * are required';
				break 1;
			}
		}
		
		if (empty($errors) === true) {
			if (user_exists($_POST['username']) === true) {
				$errors[] = 'Sorry the username \'' . $_POST['username'] . '\' is already taken.';
			}
			if (preg_match("/\\s/", $_POST['username']) == true) {
				$errors[] = 'Your username can\'t include any spaces';
			}
			if ($_POST['password'] === $_POST['username']) { 
				$errors[] = 'Your password must not be the same as your username.'; 
			}
			if (strlen($_POST['password']) < 6) {
				$errors[] = 'Your password must be atleast 6 characters';
			}
			if ($_POST['password'] !== $_POST['password_again']){
				$errors[] = 'Your password do not match';
			}
			if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){
				$errors[] = 'A valid email addres is required';
			}
			if (email_exists($_POST['email']) === true) {
				$errors[] = 'Sorry the email \'' . $_POST['email'] . '\' is already in use';	
			}
		}
	}
?>
<h3>Register</h3>
<?php
	if (isset($_GET['success'])&&empty($_GET['success'])){
		echo "you've been registed\n";
		echo "Go check your email for activating your account";
		echo ($register_data);
		die();
		
	} else {

	if(empty($_POST) === false && empty($errors) === true){
		$register_data = array(
			'username' 	 => $_POST['username'],
			'password' 	 => $_POST['password'],
			'first_name' => $_POST['first_name'],
			'last_name'  => $_POST['last_name'],
			'email' 	 => $_POST['email'],
			'email_code' => md5($_POST['username'] + microtime())
		);
	register_user($register_data);
	header('Location: Register.php?success');
	exit();
	
	} else (empty($errors) === false);{ 
		echo output_errors($errors);
	}
?>
<table cellpadding="5" cellspacing="10" id="register">
<form action="" method="post">
	<tr>
		<td>Username*: <td><input type="text" name="username"></td></td>
	</tr>
	<tr>
		<td>Password*: <td><input type="password" name="password"></td></td>
	</tr>
	<tr>
		<td>Password again*: <td><input type="password" name="password_again"></td></td>
	</tr>
	<tr>
		<td>First name: <td><input type="text" name="first_name"></td></td>
	</tr>
	<tr>
		<td>Last name: <td><input type="text" name="last_name"></td></td>
	</tr>
	<tr>
		<td>Email*: <td><input type="text" name="email"></td></td>
	</tr>
	<tr>
		<td><td><input type="submit" value="Register"></td></td>
	</tr>
	</table>
</form>

<?php
	}
?>
//users.php
<?php

	function has_access($user_id, $type){
		$user_id = (int)$user_id;
		$type 	 = (int)$type;
		return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_id` = $user_id AND `type` = $type"), 0) == 1) ? true : false;
	}

	function activate($email, $email_code){
		$email 		= mysql_real_escape_string($email);
		$email_code = mysql_real_escape_string($email_code);
		
		if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1){
			mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'");
			return true;
		} else {
			return false;
		}
	}
	
	function update_user($update_data){
		global $session_user_id;
		$update = array();
		array_walk($update_data, 'array_sanitize');
		
		foreach($update_data as $field=>$data){
			$update[] = '`' . $field . '` = \''. $data . '\'';
		}
				
		mysql_query("UPDATE `users` SET " . implode(', ',$update) . " WHERE `user_id` = $session_user_id") or die(mysql_error());
	}
	
	function change_password($user_id, $password){
		$user_id = (int)$user_id;
		$password = md5($password);
		
		mysql_query ("UPDATE `users` SET `password` = '$password' WHERE `user_id` = $user_id");
	}

	function register_user($register_data){
		array_walk($register_data, 'array_sanitize');
		$register_data['password'] = md5($register_data['password']);
		
		$fields = '`' . implode('`,`', array_keys($register_data)) . '`';
		$data = '\'' . implode('\', \'', $register_data) . '\'';
		mysql_query("INSERT INTO `users` ($fields) VALUES ($data)");
		email($register_data['email'], 'Activate your account', "Hello " . $register_user['first_name'] . ", You need to activate your account so use the link below \n\n http://quadrox.net63.net/activate.php?email=" . $register_data['email'] . "&email_code=" . $register_data['email_code'] . " \n\n - Merlieon (Quadrox Owner)");
	}

	function user_count(){
		return mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `active` = 1"),0);
	}
	
	function user_data($user_id) {
		$data = array();
		$user_id = (int)$user_id;
		
		$func_num_args = func_num_args();
		$func_get_args = func_get_args();
		
		if ($func_num_args > 1) {
			unset($func_get_args[0]);
			
			$fields = '`' . implode('`,`', $func_get_args) . '`';
			
			$data = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `user_id` = '$user_id'"));
			
			return $data;
		}
	}
	
	function logged_in(){
		return (isset($_SESSION['user_id'])) ? true : false;
	}
	
	function user_exists($username) {
		$username = sanitize($username);
		return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true : false;
	}
	function email_exists($email) {
	$email = sanitize($email);
	return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email'"), 0) == 1) ? true : false;
	}
	
	function user_active($username) {
		$username = sanitize($username);
		return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `active` = 1"), 0) == 1) ? true : false;
	}
	
	function user_id_from_username($username){
		$username = sanitize($username);
		return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, "user_id");
	}
	
	function login($username, $password){
		$user_id = user_id_from_username($username);
		
		$username = sanitize($username);
		$password = md5($password);
		
		return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) == 1) ? $user_id : false;
	}
?>

So please help me!

 

// merlieon

Link to comment
Share on other sites

and forgot

there they are connected

core/init.php includes database connection and users.php etc

<?php include 'core/init.php'?>
<?php include 'includes/overall/overall_header.php'?>
	<title> Quadrox - Register </title>
	<article>	
		<?php include 'includes/aside.php'?>	
		<section>

			<?php include 'includes/widget/register.php'?>
		</section>
	</article>
<?php include 'includes/overall/overall_footer.php'?>
Link to comment
Share on other sites

Few things to check:

 

1) make absolutely certain your connection exists -I.e mysql_error()

 

2) did u recreate the tables in the new database and r u sure the structure and naming is the same? Again running error reporting after your queries one by one will identify this.

 

3) Are you aware that mysql is deprecated ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.