Php 我的查询没有运行
我对一个php项目有一些看法。我通过HTML提交按钮调用了一个方法,但该方法没有运行,我不明白为什么。该方法包含一个将2个文本上载到SQL数据库的查询 以下是我的方法:Php 我的查询没有运行,php,Php,我对一个php项目有一些看法。我通过HTML提交按钮调用了一个方法,但该方法没有运行,我不明白为什么。该方法包含一个将2个文本上载到SQL数据库的查询 以下是我的方法: public function uploadCtrl() { if(isset($_POST['send_note'])){ $title =$_POST['title_of_note']; $text =$_POST['text_of_note']; $id = $_SESSION['user_
public function uploadCtrl() {
if(isset($_POST['send_note'])){
$title =$_POST['title_of_note'];
$text =$_POST['text_of_note'];
$id = $_SESSION['user_logged_status'];
var_dump($title, $text, $id);
$database->noteToDatabase($title, $text, $id);
}
以下是视图:
public function uploadNote(){
?>
<form action='' method='post'><br>
Title:<input type='text' name='title_of_note'><br>
Text:<input id='long_text' type='text' name='text_of_note'><br>
<input type='submit' name='send' value='SEND'><br>
<a href='?send_note'>Note save</a>
</form>
<?}
我在这里调用该方法:
if(isset($_POST['new_note'])){
$ctrl = new note_ctrl();
$ctrl->uploadNoteToDatabase();
// $ctrl->uploadCtrl();
}
我使用Mozilla Firebug检查了post方法,它看起来还可以,但是这个方法从未运行过。尝试在表单标记的action参数中提及方法名称 谢谢 您是否使用任何框架?使用$\u POST['send']而不是$\u POST['send\u note']
如果您的方法在一个类中。您可以尝试在视图中调用uploadCtrl方法
public function uploadNote(){
if(isset($_POST['send'])){$this->uploadCtrl()}
?>
<form action='' method='post'><br>
Title:<input type='text' name='title_of_note'><br>
Text:<input id='long_text' type='text' name='text_of_note'><br>
<input type='submit' name='send' value='SEND'><br>
<a href='?send_note'>Note save</a>
</form>
<?
}
若视图位于另一个类中,则需要使方法公共函数uploadCtrl{static,就像公共静态函数uploadCtrl一样{,然后你可以在视图中调用它,比如note_ctrl::uploadCtrl不起作用,很抱歉,我写错了代码,只是输入错误,因为我尝试了一个链接而不是提交按钮,但它也不起作用。链接名是send_note
form action="note_ctrl/uploadCtrl" method="post"
public function uploadCtrl(){
if(isset($_POST['send'])){
public function uploadNote(){
if(isset($_POST['send'])){$this->uploadCtrl()}
?>
<form action='' method='post'><br>
Title:<input type='text' name='title_of_note'><br>
Text:<input id='long_text' type='text' name='text_of_note'><br>
<input type='submit' name='send' value='SEND'><br>
<a href='?send_note'>Note save</a>
</form>
<?
}