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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器