这就是我想要做的: 提交表单时(通过单击按钮)
mysqli_insert_id()
函数通过PHP从MySQL获取autoincremetn ID。test.php
。以下是我的测试代码(在test.php
页面中):
<?php
// Require the configuration which controls controls error reporting:
require ('config.inc.php');
// Require the database connection:
require (MYSQL);
/* PAGE CONTENT STARTS HERE! */
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--JQUERY-->
<script type="text/javascript" src="js/jquery-1.8.2.min.js" ></script>
<script type="text/javascript">
var store_categories = [];
function init_filtering() {
store_categories.push('data1');
alert ("alert1: "+ store_categories);
}
</script>
<script type="text/javascript">$( init_filtering );</script>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$q = "INSERT INTO sms_category (sms_updated_id, category) VALUES (1, 'categories')";
$r = mysqli_query ($dbc, $q);
}
if (mysqli_affected_rows($dbc) == 1) {
?>
<script type="text/javascript">
alert ("alert2: "+ store_categories);
</script>
<?php
} // end if
?>
<form id="edit_data" action="test.php" method="post">
<input type="submit" value="Save">
</form>
</body>
</html>
现在发生了什么:
store_categories
数组store_categories
数组中的值)。所以,这是我的问题:
store_categories
数组?store_categories
数组具有其值?提前感谢您的帮助。
答案 0 :(得分:0)
可能是有效的尝试一下。 我认为在提交表单时,只会显示第二个警告。
<script type="text/javascript">init_filtering()</script>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$q = "INSERT INTO sms_category (sms_updated_id, category) VALUES (1, 'categories')";
$r = mysqli_query ($dbc, $q);
if (mysqli_affected_rows($dbc) == 1) {
?>
<script type="text/javascript">
alert ("alert2: "+ store_categories);
</script>
<?php
}
}
?>