Welcome Guest, Not a member yet? Register   Sign In
Problem with MsSQL query
#1

[eluser]rainzzz[/eluser]
I'm creating a register form and my controller is

Code:
if($this->form_validation->run() == TRUE)
        {
            $data_for_add_to_mssql= array (
    'cAccName' => $this->input->post('username'),
    'cPassWord' => md5($this->input->post('password')),
    'cEmail' => $this->input->post('email'),
    'cPhone' => $this->input->post('fone')
   );
   if($this->user_model->add_user($data_for_add_to_mssql)){
     redirect("http://failurl.com");
   }else{
    
    redirect(base_url('http://succeed.com'));
   }

and my user_model

Code:
function add_user($data_add)
    {
        $this->db->insert('Account_Info',$data_add);
    }
    function check_username($username)
    {
  $query = $this->db->query("SELECT * FROM Account_Info WHERE cAccName = '$username'");
        if($query->row()){
            return TRUE;
        }else{
            return FALSE;
        }
    }

and last when running query I get this error

Quote:Error Number: 37000

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'cAccName'.

INSERT INTO (Account_Info) (cAccName, cPassWord, cEmail, cPhone) VALUES ('John', 'e10adc3949ba59abbe56e057f20f883e', 'jogzz@yahoo.com', '123456789')

Filename: C:\xampp\htdocs\taikhoan\system\database\DB_driver.php

Line Number: 330

another issue is when I use $this->db->get('statement') and I always get the syntax error like above.

Need to be helped, thanks so much !
#2

[eluser]Tim Brownlaw[/eluser]
Hi rainzzz,

First of all I'm not a mssql user so I've not got the setup to replicate this...

From the Error Message it's showing the SQL is messed up.

It's stating that it's seeing

INSERT INTO (Account_Info cAccName, cPassWord, cEmail, cPhone) VALUES (‘John’, ‘e10adc3949ba59abbe56e057f20f883e’, ‘jogzz@yahoo.com’, ‘123456789’)
Which will cause it to go into a spin!

When the insert should be creating...

INSERT INTO `Account_Info` ('cAccName', 'cPassWord', 'cEmail', 'cPhone') VALUES (‘John’, ‘e10adc3949ba59abbe56e057f20f883e’, ‘jogzz@yahoo.com’, ‘123456789’)

I can't see anything wrong in the provided code for your Controller / Model unless I'm missing something.

Is the $this->db->get('Account_Info') displaying the same messed up SQL in the Error?

So apart from being bleeding obvious as to what it's complaining about, I'm afraid I'm falling short as to Why!

Which version of CI are you using?

Cheers

#3

[eluser]rainzzz[/eluser]
Hi Tim Brownlaw !

Firts ! Thank you in advanced ! I'm using lastest CI version. And I'm a beginner in CI. My project need to use mssql. This also the first time I do it.

I'm so sorry because my missing operator in question. So I've just modified. I meant when we use active reocord when adding data to a table the SQL Server return wrong syntax. Here is most simple examle

Code:
$query = $this->db->get('Account_Info');

SQL Server return
Quote:Error Number: 37000

[Microsoft][ODBC SQL Server Driver][SQL Server]? 2 ?: ')' ????????

SELECT * FROM (Account_Info)

Filename: C:\xampp\htdocs\taikhoan\system\database\DB_driver.php

Line Number: 330

It seem not good with the quote on Account_Info, and SQL Server doesn't accept

Use this whill be OK !

Code:
$query = $this->db->query('SELECT * FROM Account_Info');

Is anybody know what wrong with it ???




Theme © iAndrew 2016 - Forum software by © MyBB