【发布时间】:2017-03-27 22:35:03
【问题描述】:
我正在尝试通过访问 url 来找到一种自动创建数据库条目的方法。 该网址应该每天访问一次。
这是我现在正在尝试的功能:
function createMedOne() {
$medid = "1";
$mname = "Name1";
$menh = "Amount 1";
$mtime = "17:23";
$mdte = date("Y-m-d");
$mhtml = '<tr class="" id="med1">
<td><p style="font-weight: bold;">Name1</p></td>
<td>Amount 1</td>
<td>Kl: 17:23</td>
<td><button type="button" class="btn btn-warning btn-sm" style="float: right;">Sign</button></td>
</tr>';
$reg_med->addmed($medid,$mname,$menh,$mtime,$mdte,$mhtml);
}
createMedOne();
其他功能:
function addmed($medid,$mname,$menh,$mtime,$mdte,$mhtml)
{
try
{
$stmt = $this->conn->prepare("INSERT INTO tbl_med(medID,medName,medEnh,medTime,medDate,medHtml)
VALUES(:med_Id, :med_name, :med_enh, :med_time, :med_date, :med_html)");
$stmt->bindparam(":med_Id",$medid); //id of the med
$stmt->bindparam(":med_name",$mname); //name of the med
$stmt->bindparam(":med_enh",$menh); //the amount
$stmt->bindparam(":med_time",$mtime); //When to give med
$stmt->bindparam(":med_date",$mdte); //date
$stmt->bindparam(":med_html",$mhtml); //the html-code to generate content
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
当我访问该网址时,我收到以下错误:
致命错误:在 null in 上调用成员函数 addmed() test2.php 第 20 行
指的是函数createMedOne,但我找不到我错过了什么,但显然我有。
【问题讨论】:
-
我是自己自动创建的,可以帮到你吗?
-
这是一个variable scope
-
@Fred-ii-:我不怀疑这种东西存在。