简体   繁体   中英

Not able to store data into database in joomla 2.5

I've tried a lots of method to insert my data into joomla database but it's not working. Even though i have readed previous questions that has been asked by other stackoverflow members but still it is not solving my problem and also tried to understand the official joomla website but all goes in vain. Below is my code:-

defined( '_JEXEC' ) or die( 'Restricted access' );

   $app =& JFactory::getDocument();
   $page_title = $app->getTitle();

    $name = $_POST['name'];
    $class = $_POST['class'];


   $db =& JFactory::getDBO();
   echo $query = "INSERT INTO ' k2store'.'os0fr_jd'('id','name', 'class')
                  VALUES ('','$name','$class')";
                  mysql_query($query);
   $db->setQuery( $query );
   $db->query(); 







?>
<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>

Please help me to know my mistakes and any help will be appreciated the most...

So finally i have managed to found it's solution. Below is the updated 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();

       echo $name = $_POST['name'];
       echo $class = $_POST['class'];


       $db =& JFactory::getDBO();
echo $query = "INSERT INTO `#__jd` (`id`,`name`, `class`)
    VALUES ('','$name', '$class');";
$db->setQuery( $query );
$db->query(); 
?>
<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>

The main problem was that i forgot to put ` in name and also '' in $name and $class which was stated by the Nicarus(A Stackoverflow member). Thanks for the reply..:)

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