开发者

Is there any way to Get data by PHP code insted of HTML from

I'm newbie in PHP.I want to know that,I taking data by html form and a .php file. like:

<form id="form1" name="form1" method="post" action="show.php">
<strong>Please Enter the Unique id</strong><br/><br/>
Unique id:
<!-- name of this text field is "tel" -->
<input name="id" type="text" id="id" />
<p>
<input type="submit" na开发者_高级运维me="Submit" value="Submit" />
</p>
</form>
</html>

Then,I used show.php file to get the 'id'.like:

$id=$_POST['id'];

Is there any way to take input by php code??? Update:

In "C" we take ant input by this way

scanf("%d",a);

is there any way to do so in PHP.I think now all you may be clear what I'm trying to say??

Thanks Yasir Adnan.


What you are you trying to get is wrong!

HTML:- It is the communicator between the user and the browser. It displays the contents according to the user input or html code.It gets data from user or from html code.

Php :- It is the communicator between server and the browser. It has the capability of collecting from some where else other than the code like mysql data base and then uses html to display the content!

Here you are asking php to do html work which is not correct!!


the html

<input name="sb_id" type="text" id="sb_id" />

php

$id=$_POST['sb_id'];


Well, you do take the input by your php code. Your variable $id took the value of $_POST['id'] which contains the input of the textfield.

After this step you can work with the variable like any other


$id = $_POST["sb_id"]; ?

Remember that $_POST["field_name"] where field_name must be match the name attribute of your <input /> tag.

the id attribute of input tag is not sent to server inside the $_POST array. It`s typically used in client-side.


You can get data in your PHP code through GET and POST parameters. Those parameters are part of the HTTP request.

The GET parameters are in the url :

http://mywebsite.com/id=3&name=test

Then you get them using:

$id = $_GET['id'];
$name = $_GET['name'];

So you can get input data through this way when people visit the URL, call it in AJAX, or call the URL in another application (like a webservice). But no matter how it's called, it's the same for you on the PHP side.

The POST parameters are in the HTTP request, you can't pass them through the URL. You can do that by using an HTML form, or by creating the HTTP request yourself. If you are using Javascript to call your PHP code (and pass data to it), you can use AJAX to do that for example. You, in your PHP code, can get the variables this way:

$id = $_POST['id'];
$name = $_POST['name'];


If you want console-style I/O, you should probably check JavaScript/AJAX. The second one will allow you to write your own wrapper that will help you to process the input by your server "on air". The problem is, you still need to use $_POST for AJAX. And, which is more important, it's easier (and cheaper for the server) to validate and process input by JS (and to validate and process it further on the server-side after submit).

And if the question is "how can I get the variable from the needed format?", the answer is: try using regexps/parsing the string.

Oh, btw: there IS scanf() in php, and it's called 'sscanf' ('fscanf' for files).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜