我对PHP完全陌生,只是我的一个朋友要求修改他的网站,我试图这样做,因为他认为程序员可以做任何事情。
我需要创建文本字段和按钮,然后在按下按钮后将一些内容插入数据库。
我通过在default.php:中创建这样一个表单来做到这一点
<form action = 'default.php' method = 'get'>
<input type = 'text' id = 'txt_teacher_name' name = 'txt_teacher_name' />
<input type = 'submit' value = 'Set' />
</form>
当地址栏有以下地址时,该代码加载在页面中:http://onigra.net/cp2/index.php?page=default
按下按钮后,地址变为:http://onigra.net/cp2/default.php?txt_teacher_name=zxc
和我得到404错误。
我需要做些什么才能提交这份表格并保持一致?
你需要像这个一样更改你的源代码
<form action = 'index.php' method = 'get'>
<input type = 'text' id = 'txt_teacher_name' name = 'txt_teacher_name' />
<input type = 'hidden' name = 'page' value = 'default' />
<input type = 'submit' value = 'Set' />
</form>
您的url应该是http://onigra.net/cp2/index.php?page=default&txt_teacher_name=foo
index.php
<?php
if (isset($_GET(txt_teacher_name)) {
//do db insert
}
?>
<form action = 'index.php' method = 'get'>
<input type = 'text' id = 'txt_teacher_name' name = 'txt_teacher_name' />
<input type = 'submit' value = 'Set' />
</form>