1

我尝试了很多方法将我的数据插入到 joomla 数据库中,但它不起作用。尽管我已经阅读了其他 stackoverflow 成员之前提出的问题,但它仍然没有解决我的问题,并且还试图了解 joomla 官方网站,但一切都是徒劳的。以下是我的代码: -

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>

请帮助我了解我的错误,任何帮助将不胜感激...

4

1 回答 1

1

所以最后我设法找到了它的解决方案。以下是更新的代码:-

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

主要问题是我忘记在名称中加上 '' 在 $name 和 $class 中,这是 Nicarus(Stackoverflow 成员)所说的。谢谢回复..:)

于 2013-01-01T04:18:18.733 回答