Welcome Guest, Not a member yet? Register   Sign In
Database
#1

[eluser]danst[/eluser]
I can't seem to figure out a way to insert data into my table using the codeigniter

here's my code

Code:
$name = $this->input->post('name');          
$lastname = $this->input->post('lastname');
$email = $this->input->post('email');
$password = $this->input->post('password');
            
// Create a unique  activation code:
$activation = md5(uniqid(rand(), true));
            
$query_insert_user = "INSERT INTO `members` ( `Username`, `Lastname`, `Email`, `Password`, `Activation`) VALUES ( '$name', '$lastname', '$email', '$password', '$activation')";
$query = $this->db->query('$query_insert_user');

Here's my error message

Quote: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 '$query_insert_user' at line 1

$query_insert_user

Filename: /homepages/3/d358640318/htdocs/controllers/register.php

Line Number: 47

Any ideas why I'm getting this error?
#2

[eluser]wh1tel1te[/eluser]
Remove the single quotes around $query_insert_user.
#3

[eluser]danst[/eluser]
Thanks a lot. It fixed the problem!!!
#4

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...tml#insert

Code:
$data = array(
    'Username' => $this->input->post('name'),
    'Lastname' => $this->input->post('lastname'),
    'Email' => $this->input->post('email'),
    'Password' => $this->input->post('password'),
    'Activation' => md5(uniqid(rand(), true))
);

$this->db->insert('members', $data);
#5

[eluser]danst[/eluser]
Thank you for the replay. I knew I could get it to work with $this->db->insert I just feel more comfortable with writing my own sql queries rather than using codeigniter helper functions.




Theme © iAndrew 2016 - Forum software by © MyBB