如何使用提交';当页面地址设置如下时的操作;http://onigra.net/cp2/index.php?page=default"?

如何使用提交';当页面地址设置如下时的操作;http://onigra.net/cp2/index.php?page=default"?,php,button,get,Php,Button,Get,我对PHP完全陌生,只是我的一个朋友要求修改他的网站,我尝试着这样做,因为他认为程序员可以做任何事情 我需要创建文本字段和按钮,然后在按下按钮后将一些内容插入数据库 我通过在default.php中创建一个类似的表单实现了这一点: <form action = 'default.php' method = 'get'> <input type = 'text' id = 'txt_teacher_name' name = 'txt_teacher_name' />

我对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>

在index.php中显示一些代码,该表单位于哪个文件中?代码位于
default.php
。其他人已经回答了,不需要
index.php
代码,所以不再需要它了。谢谢你的关注。也谢谢你,但我不能同时接受两个答案<代码>Quỳ新罕布什尔州恩圭ễ我们是第一个,所以我给了他最好的答案。