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条)

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来