Hulu Posted July 18, 2013 Share Posted July 18, 2013 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! Quote Link to comment Share on other sites More sharing options...
NomadicJosh Posted July 18, 2013 Share Posted July 18, 2013 At first glance, what happens if in your controller you change the arrangement of your lines to this $arr =, $sql = , and then $ctr = ? Quote Link to comment Share on other sites More sharing options...
Hulu Posted July 18, 2013 Author Share Posted July 18, 2013 At first glance, what happens if in your controller you change the arrangement of your lines to this $arr =, $sql = , and then $ctr = ? Not sure let me try. Quote Link to comment Share on other sites More sharing options...
Hulu Posted July 18, 2013 Author Share Posted July 18, 2013 Not sure let me try. Nothing, same thing happens again. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 19, 2013 Share Posted July 19, 2013 (edited) 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 July 19, 2013 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Hulu Posted July 19, 2013 Author Share Posted July 19, 2013 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? Quote Link to comment 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.