简体   繁体   中英

Updating MySQL table row with Joomla MVC,

I am trying to insert values into my database, and I have followed the Joomla MVC tutorial as found here , yet I get the following SQL error:

1054 Unknown column '$client' in 'field list' SQL=INSERT INTO `p9e2i_webfoot_photo_studio_photos` (`client`,`url_name`,`file_name`) VALUES ($client,$temp_name,$file1_name) 

I am 100% certain there are client, url_name, and file_name columns in this database. The full query looks like this:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$columns = array('client', 'url_name', 'file_name');
$values = array('$client', '$temp_name', '$file1_name');
$query
  ->insert($db->quoteName('#__webfoot_photo_studio_photos'))
  ->columns($db->quoteName($columns))
  ->values(implode(',', $values));  
$db->setQuery($query);
$db->query(); 

Can someone help me identify the syntax error? I've scoured Google and Stack Exchange for hours and can't get my variables to insert into the DB. Thank you.

You should escape your values like so:

$values = array(
        $db->quote($client), 
        $db->quote($temp_name), 
        $db->quote($file1_name)
);

So simply replace you're $values array with the code above.

Also, Im not sure what Joomla version you're using, but if you're using 3.x, then replace:

$db->query(); 

with:

$db->execute(); 

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM