Question: I use Joomla 2.5 and I'm trying to insert data into my database

This is my code

```
    $db =& JFactory::getDBO();
    $query = 
    "INSERT INTO '#__restaurantes' ('nombre', 'direccion', 'localizacion', 'cod_postal', 'telefono', 'web')
    VALUES ( JRequest::getCmd('restaurante'), JRequest::getCmd('direccion'), JRequest::getCmd('localizacion'), JRequest::getCmd('postal'), JRequest::getCmd('telefonoEmpresa'), JRequest::getCmd('web') )";
    $db->setQuery( $query );
    $db->query();

```

Everything is fine and I don´t have any errors, but it doesn't insert anything.

Any idea? thanks

Answer: 
You need to put quotes around your values:

```
$restaurante = JRequest::getCmd('restaurante');
$direccion = JRequest::getCmd('direccion');
$localizacion = JRequest::getCmd('localizacion');
$postal = JRequest::getCmd('postal');
$telefonoEmpresa = JRequest::getCmd('telefonoEmpresa');
$telefonoEmpresa = JRequest::getCmd('telefonoEmpresa');
$query = "INSERT INTO '#__restaurantes' ('nombre', 'direccion', 'localizacion', 'cod_postal', 'telefono', 'web') VALUES ( '$restaurante', '$direccion', '$localizacion', '$postal', '$telefonoEmpresa', '$web' )";
$db->setQuery( $query );

```

Also, you should add this code after your query to catch any errors:

```
if ($db->getErrorNum()) {
    JError::raiseError("Error", $db->stderr());
}

```
This also should work:

```
$data =new stdClass();
$data->id = null;
$data->field1 = 'val1';
$data->field2 = 'val2';
$data->field3 = 'val3';

$db = JFactory::getDBO();
$db->insertObject( '#__mytable', $data, id );

```

stdClass is a php base class from which all other classes are extended.

'id' is the name for your primary key.