我有免费的文本框TP_ID,Deny,Level
当我输入Deny和Level的值时,我点击提交,它们存储在数据库中,TP_ID是Auto_Increment。
<form name="Permit" id="Permit" action="<?php echo JURI::current(); ?>" method="post">
<input type="text" name="TPID" value=""> <br>
<input type="text" name="Permit_or_Deny" value=""> <br>
<input type="text" name="Level" value=""> <br>
<p>input id="submit" name="submit" type="submit" value="save" /></p>
</form>
<?php
if( (isset($_POST['Permit_or_Deny'])) || (isset($_POST['Level']))|| (isset($_POST['TPID'])) )
{
$Permit_or_Deny = $_POST['Permit_or_Deny'];
$Level= $_POST['Level'];
$TPID= $_POST['TPID'];
$db =& JFactory::getDBO();
$query = "INSERT INTO tp_newedit (TP_ID, Permit_or_Deny, Level)
VALUES ('".$TPID."','".$Permit_or_Deny."','".$Level."');";
$db->setQuery( $query );
$db->query();
echo "<script>window.close();</script>";
} else
?>
有没有办法检索最后创建的ID并将其显示在文本框中?
答案 0 :(得分:0)
答案 1 :(得分:0)
答案 2 :(得分:0)
这应该有效:
SELECT LAST_INSERT_ID();
来源:
http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_last-insert-id
答案 3 :(得分:0)
您可以使用MySQL LAST_INSERT_ID()
功能。这将返回给定会话的最后插入ID。
以下是一个例子:
mysql> INSERT INTO cities VALUES (NULL, 'Banglore','India',42789);
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM cities;
+----+------------+---------+------------+
| id | city | country | population |
+----+------------+---------+------------+
| 5 | Paris | France | 11836970 |
| 6 | Nantes | France | 283025 |
| 7 | London | UK | 7556900 |
| 8 | Manchester | UK | 464200 |
| 9 | Hull | UK | 258700 |
| 11 | Banglore | India | 42789 |
+----+------------+---------+------------+
6 rows in set (0.00 sec)
mysql> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 11 |
+------------------+
1 row in set (0.00 sec)