How to transmit data from web page to script for writing to db - advice
I need to write to database from web page somewhere about 80 rows. Table is like
CREATE TABLE lan(
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
fan_coil_id integer NOT NULL,
start_time integer NOT NULL,
end_time integer NOT NULL,
mode integer NOT NULL DEFAULT 0,
day integer NOT NULL DEFAULT 0);
I have script for for writing to db, but I don't know how to transmit those values from my page to script. Do I need with GET r开发者_JS百科equest or how ? Can someone give me some advice ?
There are two ways to get information from a webpage form to your server -- GET
, variables appended to the query string of the URL, and POST
, variables in the body of the HTTP request. These populate $_GET
and $_POST
respectively in your PHP code. If you need further explanation, read the PHP manual or buy a book.
you can pass the variables through GET or POST and acceess them as array
$_GET['var_name']
Or
$_POST['var_name']
Please read about php/sql security before acting
Use $_POST
or $_GET
. See the PHP manual for how to use.
Without more details from your side – yes, you need to get values through HTTP GET or HTTP POST.
Write a form in an HTML file:
<form action="yourscript.php" method="POST">
<input type="text" name="foo"/>
<input type="submit"/>
</form>
Then access the values through your PHP script:
$_POST['foo']
Similarly, when you use method="GET"
, you'd access them in $_GET
. Read up on writing HTML forms on how to pass the data.
精彩评论