Quote from Dark_Marine_123
Im no good at C++ or PHP, but very good at VB, God can someone leave an answer instead of critism?
VB is a High-End language, meaning its
simplistic.
If you want to write anything that anyone on the internet would like (because it works for them) learn either PHP or ASP.Net, for starters...
Then maybe learn yourself some VB.Net, or maybe even C#.Net...
Here is how you'd "accept a variable from a form" with PHP:
// Check for a username
if (eregi ("^[[:alnum:]_]{4,20}$", stripslashes(trim($_POST['username']))))
{
$u = escape_data($_POST['username']);
} else {
$u = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid username!</font></p>';
}
<p><b>Username:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /> </p>
That's how you'd accept, and pass a variable in a form (it also is a sticky form)
All this stuff:
// Check for a username
if (eregi ("^[[:alnum:]_]{4,20}$", stripslashes(trim($_POST['username']))))
{
$u = escape_data($_POST['username']);
} else {
$u = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid username!</font></p>';
}
is PHP.
All this stuff:
<p><b>Username:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /> </p>
is HTML mixed with a simple PHP conditional script.
If I knew any ASP, I'd show you that, but I don't...
Let me explain the PHP to you:
if (eregi ("^[[:alnum:]_]{4,20}$", stripslashes(trim($_POST['username'])))) is an "if, else conditional".
Meaning, "if (function eregi ("beginning of string[[class any letter or number]extra character allowed within this conditional]{minimum number of characters needed to meet conditional, maximum number of characters allowed for conditional}end of string", function stripslashes(trim($_POST['username']))))
So if (eregi ("^[[:alnum:]_]{4,20}$", stripslashes(trim($_POST['username'])))), checks to see if a string with any letter or number, including an underscore (_) is passed, and if the condition is met, it will stripslashes (has to deal with Magic Quote stuff) and trim (take out unnecesary white-space) the variable $_POST['username']
We defined "username" inside of our HTML form (notice the bolded area):
<p><b>Username:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /> </p>
$_POST is a global function(?) that catches the "methed post" from your HTML form (if you use the method post that is...)
It'd be best to use post instead of get in your "form action".. Get will have all the variable information in the URL... Its just for security reasons.
So anyways: if your condition is met (the condition is that someone put a username in the "username" input field in your form, and they used any number and letter and/or the _ is included), the variable $u, will have the value: escape_data($_POST['username']);
The $_POST['username'] will be whatever is inserted within the bolded area:
<p><b>Username:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /> </p>
so if I input Kellimus, it would look something like this: $u = escape_data($_POST['Kellimus']);
If my condition is not met, thats when the "else" would happen.
So if I didn't input a name into the "username" text field, it would return $u as FALSE, then output (in HTML):
<p><font color="red" size="+1">Please enter a valid username!</font></p>
Does that make sense? I know that eregi, and all that stuff is confusing to beginners, but once you use it a while, you'll understand....
Post has been edited 3 time(s), last time on Nov 6 2007, 10:34 pm by Kellimus.
None.