Forum Moderators: coopster

Message Too Old, No Replies

php newbie- dont even know what to ask for help with! :)

         

raze75

3:12 am on Mar 30, 2004 (gmt 0)

10+ Year Member



hi :)
so im trying to make this option: <snip> a little more easy by instead of having the user click on a number which takes them to an anchor on an html page- having them rather enter in the number of their bday in a field and when they hit enter have the prediction displayed on the page. however i have no clue about php. i do not even really know what question to ask to search for a tutorial about this.

really i just want to be able to have a user enter in a number in a field and upon hitting enter have that number pull up and display data from a text file (i guess)- does this make sense- it seems easy enough but i dont know what to ask for help with cause i dont really know anything about php! help :)

[edited by: jatar_k at 5:59 pm (utc) on Mar. 30, 2004]
[edit reason] no personal urls thanks [/edit]

coopster

3:04 pm on Mar 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, raze75!

Create a form [php.net].
Create your text files and store them on your server.
Use php to process the form submittal by edit checking the user-supplied data, opening and reading the correct "date" file, and displaying the associated context.

Here is a working example (you'll have to create your text files first, of course). The links are to the PHP manual that will further explain the functions and control structures:

<?php 
$birthdate = (isset [php.net]($_POST['birthdate'])) ? [php.net] $_POST['birthdate'] : '';
?>
<html><head><title>birthdate</title></head><body>
<h1>birthdate</h1>
<form action="<?php print $_SERVER [php.net]['PHP_SELF'];?>" method="post">
<fieldset>
<legend>birthdate</legend>
Birthdate: <input name="birthdate" name="birthdate"
type="text" value="<?php print $birthdate;?>" /><br /><br />
<input type="submit" name="Submit" value="Submit" />
</fieldset>
</form>
<fieldset>
<legend>Posted Form Values<legend/>
<?php
if (isset [php.net]($_POST['Submit'])) {
if ($birthdate > 0 and $birthdate < 31) { // edit checking
print [php.net] '$birthdate is ' . $birthdate . '<br />';
$myfile = $birthdate . '.txt'; // (i.e. '17.txt')
if ($text = @ [php.net]file_get_contents [php.net]($myfile)) {
print nl2br [php.net]($text);
} else {
print 'Sorry, we do not have any content for your birthday!';
}
} else {
print 'You did not supply a valid birth date!';
}
}
?>
</fieldset>
</body></html>