如何在另一个页面中获取文本框的值(php)[关闭]

i have a function for creating 'textbox' in php

function txtbox($capt,$tname,$defvalue,$readonly='')
{
            print "<table><tr><td align=right width=300><font color=black>$capt :</td><td align=left><input type='text' name='txt'  $tname value='$defvalue' $readonly></td></tr></table>";
}

and called the function like:

txtbox('Courid','courid','');  where 2nd parameter is the name of the text box.

Could anyone please tell me how to get the values of the above text box in another page????

You could store the text box values in a cookie. Just make sure the data has been properly sanitized, maybe using the htmlentities() method, before setting it in the cookie.

You will have to wrap your input in a form with a submit button. Then in your php script you will be able to get the variable at the next page refresh (i.e. when the form is submitted):

In the html:

<form action="name_of_your_script.php" method="POST">
    <input type='text' name='txt' value='$defvalue' $readonly>
    <input type="submit" value="Submit">
</form>

(replace name_of_your_script.php by the actual name of your php file)

In your php script you can get the txt input field like this:

$entered_text = $_POST['txt']

You could also use the GET method, which passes the form values through the URL, just replace POST by GET in both example if you want.

More information about forms

And do not forget to sanitize all the values submitted to avoid any security problem!