Hi there,
I’m currently working with MODx Evolution and in one of my snippets I’m trying insert data into a database table.
So using $result = $modx->db->query($query); should normally do the trick.
My query is:
$query = "INSERT INTO $dbase.`poll_votes` (poll_opt_id, ip) VALUES (’$v_vote’, ’$v_ip’);";
But I keep getting this error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
I just can’t seem to save it like this.
But when I change VALUES in the query to anything else, for example to VALUE, it has no problems with saving the snippet. Of course the next problem is that the query is not right.
Does anybody know what I can do to get it to work?
Thanks in advance!
Give this a try
<?php
// set up the fields
$fields = array(
'oll_opt_id' => $v_vote,
'ip' => $v_ip
);
// do the insert
$insert = $modx->db->insert($fields, $modx->getFullTableName('poll_votes'));
// do stuff if the insert was ok
if($insert){
// do stuff here
}
I needed to alter it a little, because ’poll_votes’ wasn’t a default MODx table, so I changed $modx->getFullTableName(’poll_votes’) to "$dbase.poll_votes" and then it did the trick for me.
Thanks a lot!