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

[eluser]CodyPChristian[/eluser]
So I'm having some werid issues with a function. All of the code is bellow. I can explain what the freakauth stuff does if needed Wink.

This is how the table is setup: id,nick,from,subject,date,message,new

Here is my function:
Code:
function send_new()
    {
        $data['nick'] = $this->freakauth_light->getUserName();
        
        $data['base_url'] = $this->config->item('base_url');
        
        $this->db->insert('messages', $_POST);

        //print_r($_POST);
        redirect('admin/messages');
  
    }

Here is my view:

Code:
<?=form_open('admin/messages/send_new');?>
    
    <?=form_hidden('id', '');?>

    <p>To:&lt;input type="text" name="nick" /&gt;</p>

    &lt;?=form_hidden('from', $this->freakauth_light->getUserName());?&gt;
    
    <p>Subject:&lt;input type="text" name="subject" /&gt;</p>
    <p>Date:&lt;input type="text" name="date" /&gt;</p>
    <p>Message:<br />&lt;textarea name="message" rows="15" cols="60" &gt;&lt;/textarea&gt;</p>
    
    &lt;?=form_hidden('new', '1');?&gt;

    <p>&lt;input type="submit" value="Send Message" /&gt;</p>
    
    &lt;/form&gt;

and here is my error:
Code:
An Error Was Encountered
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 'from, subject, date, message, new) VALUES ('', 'Eckypro', 'CodyPChristian', 'Sub' at line 1

INSERT INTO messages (id, nick, from, subject, date, message, new) VALUES ('', 'Eckypro', 'CodyPChristian', 'Subject here', '7/11/2007', 'message here ;)', '1')
#2

[eluser]BLymoth[/eluser]
It seems like its treating the "from" field as the reserved word in SQL... try renaming your field to something else, like sender, source, originator.. whatever
#3

[eluser]CodyPChristian[/eluser]
Thanks, I changed it and that fixed the problem Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB