我在Moodle中有一个页面,用户可以通过JQuery添加连续的行,每次单击“保存”按钮时,表单中输入的数据都将写入数据库,但我收到以下错误消息:
调试信息:SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以便在附近使用正确的语法 (订单)价值观(' 1','简介音频1',' 1')'在第1行
INSERT INTO mobile (week,title,order) VALUES(?,?,?)
[array (
0 => 1,
1 => 'Introduction Audio 1',
2 => '1',
)]
要追加连续行的表单:
<form method="post" action="processMobileApp.php">
<br/>
<span class="add-week" style="float:right;"><input type='button' value="Add a New Week" style="font-weight:bold; font-size:17px;"/> </span>
<span class="add-row" style="float:right;"><input type='button' value="Add New Row" style="font-weight:bold; font-size:17px;"/> </span>
<span style="float:right;"><input type='submit' value="Save" style="font-weight:bold; font-size:17px;"/></span>
<br/><br/>
<table class="row-list" cellspacing="1" cellpadding="0">
<br/>
<tr>
<th>Week 1 Title</th><th>Order</th><th>Edit</th><th>Delete</th><th>Upload</th>
</tr>
<tr>
<td>
<input type="text" name="title0" />
</td>
<td>
<input type="text" name="order0" />
</td>
<td>
<a href="editapp.php"><u>Edit</u></a>
</td>
<td>
<a href="deleteapp.php"><u>Delete</u></a>
</td>
<td>
<a href="uploadapp.php"><u>Upload</u></a>
</td>
</tr>
</table>
</form>
JQuery代码:
<script>
jQuery(function(){
var counter = 1;
jQuery('span.add-row').click(function(event){
event.preventDefault();
counter++;
var newRow = jQuery('<tr><td><input type="text" name="title' +
counter + '"/></td><td><input type="text" name="order' +
counter + '"/></td><td><a href="editapp.php"><u>Edit</u></a></td></td><td><a href="deleteapp.php"><u>Delete</u></a></td><td><a href="uploadapp.php"><u>Upload</u></a></td></tr>');
jQuery('table.row-list').append(newRow);
});
var count = 2;
jQuery('span.add-week').click(function(event){
event.preventDefault();
counter++;
var newWeek = jQuery('<tr><th>Week ' + (count++) + ' Title</th><th>Order</th><th>Edit</th><th>Delete</th><th>Update</th></tr><tr><td><input type="text" name="title' +
counter + '"/></td><td><input type="text" name="order' +
counter + '"/></td><td><a href="editapp.php"><u>Edit</u></a></td><td><a href="deleteapp.php"><u>Delete</u></a></td><td><a href="uploadapp.php"><u>Upload</u></a></td></tr>');
jQuery('table.row-list').append(newWeek);
});
});
</script>
处理表单数据并将其提交到数据库的页面:
<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
global $DB;
$countWeek = 1;
$counter = 0;
$week = $countWeek++;
$title = required_param("title0", PARAM_TEXT);
$order = required_param("order0", PARAM_TEXT);
$counter+1;
$record2 = new stdClass();
$record2->week = $week;
$record2->title = $title;
$record2->order = $order;
$record2->displayorder = '10000';
// Insert one record at a time.
$lastinsertid2 = $DB->insert_record('mobile', $record2);
if(!$lastinsertid2)
{
echo "Could not insert";
}
else
{
echo "Successful";
}
?>
这是包含表单的页面的屏幕截图:
请帮忙吗?感谢。
答案 0 :(得分:1)
答案 1 :(得分:1)
您应该使用xmldb编辑器创建install.xml文件,该文件为您的本地插件创建表。这将检查表格和字段名称中的保留字 - https://docs.moodle.org/dev/XMLDB_editor
可通过网站管理员访问 - &gt;发展 - &gt; xmldb编辑。
避免使用反引号,因为它们与数据库有关。 Moodle支持几个数据库而不仅仅是mysql。最好继续使用$ DB-&gt; insert_record()函数。