Help with getting input from user

Hi,

I’m writing my first php program. I’ve had some programming experience with C++, but I’m having a bit of trouble understanding how php does input. I’m using fgets to read input from the user. I believe fgets reads everything up to the newline character? So I want to get the user to type in his last and first name, and store them in different variables. The only way I see to do this is to use fgets, then explode to split the first name and last name, then store them. Is there a way to read input like in C++, where it reads up to white space, then the next variable stores the next string?

Sorry if my explanation is unclear, I just recently got into programming, so I’m relatively new the terms and concepts. Thank you for any help.

u read user input from fgets ?
and what are , tags are supposed to do ?
you should process input from form ,

User will input information into a form that has been made in html

Subject of email:

Body of email:

When this form button submit is click the information will be sent via post to the sendemail.php

You will then need to read the post information using a super global $_post

[php]$subject = $_POST[‘subject’]; // reading the post data and assigning var $subject to hold the value.
$text = $_POST[‘body’]; // reading post data and assigning var $text to hold the value.[/php]

In addition to forms, you can also pass information to PHP through the URL with a query string. If you ever notice a url with a question mark, followed by some variable assignment like string, you have seen an example of passing info through the URL. An example URL would be like:
www.mysite.com/index.php?var=value

notice the var=value part. That sets the variable “var” to the value “value”

In PHP, you access the values via the $_GET super global. So if you went to the URL above, the code that the page ran may do something like
[php]
$var = $_GET[‘var’];//format is $_GET[‘name of variable in query string’]

echo “The value of the var variable in the query string is: $var”;
[/php]

You can also send information to the $_GET super global by setting your form method to get (instead of the default, post, which the poster above me explains)

You can also use the Command Line Interface (or CLI) if you want to produce PHP scripts without needing a web server (you still need to PHP interpreter)

A tutorial on using the PHP CLI can be read here: http://www.php-cli.com/php-cli-tutorial.shtml

Sponsor our Newsletter | Privacy Policy | Terms of Service