I am totally new to PHP, just one of my friends asked to modify his site and I trying to do this, since he think programmers can do everything.
I needed to create text field and button, then insert something into database after button is pressed.
I done it that by creating a form like that in 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>
And this code is loaded in page when address bar have this address: http://onigra.net/cp2/index.php?page=default
After pressing the button address changes to this: http://onigra.net/cp2/default.php?txt_teacher_name=zxc
and I getting 404 error.
What I need to do to make submit this form and stay on same page?
You need change to your source like this
<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>
Your url should be 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>