dshtze500055 2012-02-23 13:01
浏览 37
已采纳

写信给Joomla数据库

I'm a front end dev, so my PHP is a bit lacking and I'm stuck.
I'm trying to write some data from a form into the Joomla database.
It's only an email address so not complicated. I've created a form and a table in the database to hold the email addresses. However I can't get it to write to the database and I'm not sure what I'm missing.
I'm not sure what classes I need to include in my code. I'm including joomla/factory so I'm not getting an error telling me the JFactory is not an object, but I don't know if I need to include anything else.

Here's my PHP code:

$emailAdd = $_POST['email'];

require_once ('../../libraries/joomla/factory.php');

$db =& JFactory::getDBO();
$query = "INSERT INTO '#__pdfemails' ('emailaddress')
    VALUES ('thevalue')";
$db->setQuery($query);
$db->query();

I don't get any kind of error at all, but it's not writing to the database.

Can anyone help please?

  • 写回答

2条回答 默认 最新

  • duanmuyao0463 2012-02-24 18:34
    关注

    You have an error in your SQL. This:

    $query = "INSERT INTO '#__pdfemails' ('emailaddress')
    VALUES ('thevalue')";
    

    should be this:

    $query = "INSERT INTO '#__pdfemails' (emailaddress)
    VALUES ('thevalue')";
    

    Note the lack of single-quotes around the column name.

    If you ever get an error like this again, try executing the SQL directly in MySQL first. In a Joomla environment, there can be many points at which errors get 'hidden'. That's very sensible for a live site, although you should be able to configure a development site to show SQL errors to ease troubleshooting.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据