繁体   English   中英

如何提交表单并使用 php 在 mysql 数据库表中插入新行?

[英]How can I submit a form and use php to insert a new row into a mysql database table?

下面是我的 PHP 代码。 我想我很接近但我不明白为什么当我单击表单上的提交按钮时它没有在我的 PHP 代码中输入我的if (isset($_POST['addFormula']))语句来执行插入.

alert('我在这里!!!'); alert('添加成功'); alert('添加公式时出错...');

这是我的 html 代码

<table style="width:100%"> <tr> <td> <form method="post"> <h3 style="color:#a5a5a5; margin:5px 0 0 0">Name:</h3> <input type="text" name="name"><br> <h3 style="color:#a5a5a5; margin:5px 0 0 0">Formula:</h3> <input type="text" name="formula"><br> <h3 style="color:#a5a5a5; margin:5px 0 0 0">Category:</h3> <input class="radio-button" type="radio" id="math" name="category" value="Math" checked> Math <input class="radio-button" type="radio" name="category" value="Physics"> Physics <h3 style="color:#a5a5a5; margin:5px 0 0 0">Description:</h3> <textarea class="description-textarea" name="description" ></textarea><br> <tr> <td class="cancel-button"> <button type="button" id="cancelAdd">Cancel</button> </td> <td class="save-button"> <button type="submit" name="addFormula" id="add">Save</button> </td> </tr> </form> </td> </tr> </table>

试试这个,我在表单中添加了 action 元素以加载相同的 php 页面。 如果 PHP 脚本不在同一个文件中,您可以将其更改为特定页面。 例子:

<form method="post" action='action.php'>

<form method="post" action=<?php echo $_SERVER['PHP_SELF'];?>>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM