Welcome Guest, Not a member yet? Register   Sign In
Problems with mysql syntax? I don't think so...
#1

[eluser]selman555[/eluser]
Hi everyone,

I'm having some trouble making a login form for my site.

I already have a fully working registration form (data goes to the database and back successfully (included in code))
I have a user controller "user" that looks like this: (read the comments in the code for explenations).
Code:
function register()
{
    //form validations ... not needed for my question, except this one:
    $this->form_validation->set_rules('gebruikersnaam', 'Gebruikersnaam', 'xss_clean|trim|required|alpha_numeric|min_length[5]|max_length[30]|callback_usernameNotExists');
    //notice the callback_usernameNotExists.
    //also, my password has xss_clean enabled (so it's hashed in the database)

    $activatieCode = $this->randomString(10); //generating activationcode here

    $this->User_model->registerUser($gebruikersnaam, $paswoord, $naam, $voornaam, $email, $activatieCode); //registerUser
}

function usernameNotExists($gebruikersnaam) {
    $this->form_validation->set_message('usernameNotExists', "De gebruikersnaam '$gebruikersnaam' bestaat al, probeer een andere naam.");
    if ($this->User_model->checkExistsUsername($gebruikersnaam)) { //checkExistingUsername
        return false;
    } else {
        return true;
    }
}

//function for the login procedure
function log() {
    $this->form_validation->set_rules('paswoord', 'Paswoord', 'xss_clean|trim|required|alpha_numeric|min_length[6]|max_length[30]');
    if ($this->User_model->checkLogin($gebruikersnaam, $paswoord)) { //checkLogin
        $queryStr = "update Gebruikers set logged = 1 where Gebruikersnaam = ?";
$this->db->query($queryStr, $gebruikersnaam);
$this->index();
    } else {
$this->load->view('view_login');
    }
}
That's it for my controller
Now here's the usermodel "user_model".
Code:
function registerUser($gebruikersnaam, $paswoord, $naam, $voornaam, $email, $activatieCode) {
$secpas = sha1($paswoord);
$queryStr = "insert into gebruikers (Gebruikersnaam, Paswoord, Naam, Voornaam, Email, Activatiecode) VALUES (?, ?, ?, ?, ?, ?)";
$result = $this->db->query($queryStr, array($gebruikersnaam, $secpas, $naam, $voornaam, $email, $activatieCode));
}

function checkExistsUsername($gebruikersnaam) {
    $queryStr = "select Gebruikersnaam from gebruikers where Gebruikersnaam = ?";
    if ($this->db->query($queryStr, $gebruikersnaam)) {
return true;
    } else {
return false;
    }
}

function checkLogin($gebruikersnaam, $paswoord) {
    $queryStr = "select Gebruikersnaam from gebruikers where Gebruikersnaam = ? and Paswoord = ?";
    if ($this->db->query($queryStr, $gebruikersnaam, $paswoord)) {
return false;
    } else {
return true;
    }
}

So, the registration part is working (almost the same mysql syntax as login(???)).
I get this standard error message (1064):
Code:
A database error occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? and Paswoord = ?' at line 1

select Gebruikersnaam from gebruikers where Gebruikersnaam = ? and Paswoord = ?

Filename: C:\xampp\htdocs\CodeIgniter\E-Cards\system\database\DB_driver.php

Line Number: 330


Messages In This Thread
Problems with mysql syntax? I don't think so... - by El Forum - 01-22-2012, 07:33 AM
Problems with mysql syntax? I don't think so... - by El Forum - 01-22-2012, 09:05 AM
Problems with mysql syntax? I don't think so... - by El Forum - 01-23-2012, 06:13 AM
Problems with mysql syntax? I don't think so... - by El Forum - 01-28-2012, 07:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB