Jump to content

Account Creation


Hulu

Recommended Posts

I am having a bit of trouble getting this register function to work. Its for a game server so the password has to be md5 and salted with the username. Here is the function part of the Register.
This is using MVC by the way.

<?php

class Register extends MainController{
	function __construct(){
						debug_backtrace();
			parent::__construct();
			$this->view->url	=	$this->config->url;
			$this->view->ID 	  = get_class($this);
			$this->view->Title = "Royal JD > Create Account";
			$this->view->render('Register');

	function Create_Account(){
		$username = isset($_POST['username']) ? $_POST['username'] : '';
		$email = isset($_POST['email']) ? $_POST['email'] : '';
		$password = isset($_POST['password']) ? $_POST['password'] : '';
		$username = mysql_real_escape_string(StrToLower(Trim($username)));
		$password = mysql_real_escape_string(StrToLower(Trim($password)));

		$this->view->salt = $username;
		$this->view->salt = $username.$password;
		$this->view->salt = md5($this->view->salt);
		$this->view->salt = "0x".$this->view->salt; //Salts the password in md5.
		
			$sql = "INSERT INTO users WHERE name = :name AND passwd = :passwd AND idnumber = :idnumber AND email = :email";
			$arr = array(":name" => $username, ":email" => $email, ":idnumber" => $password, ":passwd" => $this->view->salt);
			$ctr = $this->database->DBQry($sql,$arr);
		}
	
}
}
?>

the database.php looks like this:

<?php


	class Database extends PDO{
		
		// Initialize
		const DBHOST  = "localhost";
		const DBNAME  = "test";
		const DBUSER  = "root";
		const DBPASS  = "123";
		
		const SELECT  = "SELECT * FROM ";
		const INSERT  = "INSERT INTO ";
		const UPDATE  = "UPDATE ";
		const DELETE  = "DELETE FROM ";
		
		
		// Make Connection
		function __construct(){
			parent::__construct("mysql:host=".self::DBHOST.";dbname=".self::DBNAME,self::DBUSER,self::DBPASS);
		}
		
		// Query
		function DBQry($sql,$arr){
			$sth = $this->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
			$sth->execute($arr);
			$rs = $sth->fetchAll();
			return $rs;
		}
		
		// Count
		function DBCtr($sql,$arr){
			$sth = self::prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
			$sth->execute($arr);
			return $sth->rowCount();
		}
		
		// Last ID
		function DBLst($table){
			$sql = $this->SELECT.$table." ORDER BY id DESC LIMIT 1";
			$arr = array();
			$ctr = self::DBCtr($sql,$arr);
			$rs =  self::DBQry($sql,$arr);
			return ($ctr > 0) ? $rs[0]['id'] : 0;
		}
		
		// Insert
		function DBIns($arr,$tbl){
			$fld = 	implode(",",array_keys($arr));
			$sql =  self::INSERT.$tbl." (".str_replace(":","",$fld).")
					 VALUES(".$fld.")";
					 
			$sth = $this->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
			$sth->execute($arr);
		}
		
		// Update
		function DBSet($arr,$tbl,$whr = ''){
			$stmt = array();
			foreach($arr as $fld => $val){
				$stmt[] =  str_replace(":","",$fld)." = ".$fld;
			}
			$stm =  implode(",",$stmt);
			$sql =  self::UPDATE.$tbl." SET ".$stm.' '.$whr;
			$sth =  $this->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
			$sth->execute($arr);
		}
		
		// Delete
		function DBDel($tbl,$whr = ''){
			$sql = self::DELETE.$tbl." ".$whr;
			$this->exec($sql);
		}
		
		
	
		
	}



?>

My issue is that its not sending any info to the database.

Any help will be appreciated! 

Link to comment
Share on other sites

your syntax for the insert query is incorrect and you are not testing if the query failed due to an error. there is no WHERE clause in an insert query.

 

it appears you are trying to use the INSERT ... SET ... syntax -

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
SET col_name={expr | DEFAULT}, ...
[ ON DUPLICATE KEY UPDATE
col_name=expr
[, col_name=expr] ... ]

also, AND is a logical operator. a comma , is used to separate a list.

Edited by mac_gyver
Link to comment
Share on other sites

your syntax for the insert query is incorrect and you are not testing if the query failed due to an error. there is no WHERE clause in an insert query.

 

it appears you are trying to use the INSERT ... SET ... syntax -

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
SET col_name={expr | DEFAULT}, ...
[ ON DUPLICATE KEY UPDATE
col_name=expr
[, col_name=expr] ... ]

also, AND is a logical operator. a comma , is used to separate a list.

Can you give me an example of an INSERT query?

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.