EchoFool Posted February 20, 2012 Share Posted February 20, 2012 Hey I have a script that registers users, but i cannot work out why it will not process the information. I echo'd the variables and its all correct yet it just will not do it =/ This is the script i have - was hoping some one might be able to see the mistake: database script: <?php class DB extends mysqli { public function execute($query) { echo $query; return $this->query($query); } public function qstr($str) { if (is_array($str)) { return $this->qstrArr($str); } return "'{$this->real_escape_string($str)}'"; } public function qstrArr($arr) { foreach ($arr as $key => $value) { $arr[$key] = $this->qstr($value); } return $arr; } ?> Register Process <?php $pass = $db->qstr($_POST['pass']); $user = $db->qstr($_POST['user']); $email = $db->qstr($_POST['email']); $db->execute("INSERT INTO users (username,pass,email) VALUES ($user,$pass,$email);"); ?> On the database script i echo the query and it displays like this: INSERT INTO users (username,pass,email) VALUES ('test','098f6bcd4621d373cade4e832627b4f6','test@test.com'); So why could it not be working =/ i get no error displaying by the way. Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/ Share on other sites More sharing options...
PeoMachine Posted February 20, 2012 Share Posted February 20, 2012 The query is right. I think the problem is the connection... How you're getting connected? Try a var_dump() on the return of $db->execute() too. Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/#findComment-1319065 Share on other sites More sharing options...
EchoFool Posted February 20, 2012 Author Share Posted February 20, 2012 I got this - its a bit ugly to read: object(DB)#2 (17) { ["affected_rows"]=> int(-1) ["client_info"]=> string(50) "mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $" ["client_version"]=> int(50008) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(1054) ["error"]=> string(37) "Unknown column 'pass' in 'field list'" ["field_count"]=> int(1) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.5.16" ["server_version"]=> int(50516) ["sqlstate"]=> string(5) "42S22" ["protocol_version"]=> int(10) ["thread_id"]=> int(48) ["warning_count"]=> int(0) } I'm connected like this: <?php $db['default']['hostname'] = "localhost"; $db['default']['username'] = "root"; $db['default']['password'] = "**********"; // removed $db['default']['database'] = "table_name"; $db['default']['dbdriver'] = "mysqli"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/#findComment-1319066 Share on other sites More sharing options...
PeoMachine Posted February 20, 2012 Share Posted February 20, 2012 Unknown column 'pass' in 'field list' ... Thats your error . Try it again to see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/#findComment-1319067 Share on other sites More sharing options...
EchoFool Posted February 20, 2012 Author Share Posted February 20, 2012 Ohh i see. So how can i enable error reporting like that by default? Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/#findComment-1319068 Share on other sites More sharing options...
PeoMachine Posted February 20, 2012 Share Posted February 20, 2012 INSERT INTO users (username,pass,email) ... show me the table creating SQL... Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/#findComment-1319069 Share on other sites More sharing options...
EchoFool Posted February 20, 2012 Author Share Posted February 20, 2012 INSERT INTO users (username,pass,email) ... show me the table creating SQL... Beat me to my edit.. yeah i see it now - is there a way i can add an error reporting for it so i know in future? Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/#findComment-1319070 Share on other sites More sharing options...
PeoMachine Posted February 20, 2012 Share Posted February 20, 2012 For development you can set display_errors = on, on the php.ini, or use ini_set('display_errors', 'on') on the files you wanted. In this case, a little echo on the return of $db->execute() could give you the answer. Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/#findComment-1319071 Share on other sites More sharing options...
EchoFool Posted February 20, 2012 Author Share Posted February 20, 2012 i thought error display would not apply to non PHP related issues such as query errors? Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/#findComment-1319072 Share on other sites More sharing options...
PeoMachine Posted February 20, 2012 Share Posted February 20, 2012 Well, it depends of the error... sometimes the adapter give an error (like connection errors), and sometimes you have to find him (like this case). Quote Link to comment https://forums.phpfreaks.com/topic/257346-wheres-my-mistake/#findComment-1319073 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.