Reputation: 67
I am working on a joomla 2.5 website & I am trying to insert values in database entered in the form on form submit. But I dont know why they are not inserting in the DB. Please help me out guys.
I've tried many different ways but I am not getting where I am going wrong.
This is my code:
if(isset($_POST["buttonSubmit"]))
{
$name = $_POST["name"];
$location = $_POST["location"];
$email = $_POST["email"];
echo $name;
$db =& JFactory::getDBO();
echo $query = "INSERT INTO '#__pxa_map' ('name', 'location','email') VALUES ($name, $location,$email)";
$db->setQuery( $query );
$db->query();
}
How to insert values in to database in joomla 2.5
Upvotes: 0
Views: 3919
Reputation: 91792
You should add error handling and use prepared statements (preferably, don't know how that works in Joomla 2.5), but your query is wrong:
$db->quote()
to prevent sql injection.So it should look like:
$db = JFactory::getDbo();
$name = $db->quote($_POST["name"]);
// etc.
$query = "INSERT INTO `#__pxa_map` (`name`, `location`,`email`) VALUES ('$name', '$location','$email')";
Upvotes: 3