2 Replies - 5024 Views - Last Post: 31 December 2012 - 09:15 PM Rate Topic: -----

#1 phplearner_null  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-December 12

Inserting data into database is not working in joomla 2.5

Posted 30 December 2012 - 09:38 PM

Dear Folks, I've tried a lots of method to insert my data into joomla database but it's not working. Below is my code:-

<?php
/**
 *
 * @file        $Id: default.php 0.0.2 2012-12-28 00:00:00 Joydeep Banerjee $
 * @package	    School Mangement System 
 * @version     0.0.2
 * @description Simple School Management System component for joomla 2.5
 * @copyright	  Copyright © 2012 - All rights reserved.
 * @license		  GNU General Public License v2.0
 * @author		  Joydeep Banerjee
 * @author mail	joy@vividtechno.com
 * @website		  http://www.indiawebsitedesigndevelopment.com
 *
 **/

  // No direct access
  defined( '_JEXEC' ) or die( 'Restricted access' );
       $app =& JFactory::getDocument();
       $page_title = $app->getTitle();
       $db =& JFactory::getDBO();
        $name = $_POST['name'];
       $class = $_POST['class'];
       
       
       $db =& JFactory::getDBO();
$query = "INSERT INTO `#__jd` (`id`,name`, `class`)
    VALUES ('',$name, $class);";
$db->setQuery( $query );
$db->query(); 
       
       
       
      
         
	// YOUR CUSTOM CODE HERE

?>
<form action="index.php" method="post" name="adminForm">
<input type="hidden" name="option" value="com_sms" />
<input type="hidden" name="view" value="Sms" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
Name:&nbsp;<input type="text" name="name">
Class:&nbsp;<input type="text" name="class">
<input type="submit" value="Register" name="register">
</form>



I want to know what is my mistake and how to insert it successfully. Thanks for any kind of help....

Is This A Good Question/Topic? 0
  • +

Replies To: Inserting data into database is not working in joomla 2.5

#2 BerndB  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-December 12

Re: Inserting data into database is not working in joomla 2.5

Posted 31 December 2012 - 08:59 AM

Hi,

you forgot the ` before the name field

$query = "INSERT INTO `#__jd` (`id`,name`, `class`)
    VALUES ('',$name, $class);";


so i mean it will work:
$query = "INSERT INTO `#__jd` (`id`,`name`, `class`)
    VALUES ('',$name, $class);";



Bernd

This post has been edited by Atli: 31 December 2012 - 09:16 AM
Reason for edit:: Please use [code] tags when posting code.

Was This Post Helpful? 1
  • +
  • -

#3 phplearner_null  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-December 12

Re: Inserting data into database is not working in joomla 2.5

Posted 31 December 2012 - 09:15 PM

View PostBerndB, on 31 December 2012 - 08:59 AM, said:

Hi,

you forgot the ` before the name field

$query = "INSERT INTO `#__jd` (`id`,name`, `class`)
    VALUES ('',$name, $class);";


so i mean it will work:
$query = "INSERT INTO `#__jd` (`id`,`name`, `class`)
    VALUES ('',$name, $class);";



Bernd

Thanks BErndB for the reply. Yeah, i'd forgot to insert ` in name and also i forgot to put '' in $name and $class. That's why it was not working, so i have changed it and now everything is working well....Below is the update code.
       $db =& JFactory::getDBO();
 $query = "INSERT INTO `#__jd` (`id`,`name`, `class`)
 VALUES ('','$name', '$class');";
 $db->setQuery( $query );
 $db->query();

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1