My first PHP
PHP Code
+ 0 likes
Please Register to submit score.
| Average Score | 0.0 (of 0 scores) |
| Date Added | Dec 12, 2008 |
| Last Updated | Dec 12, 2008 |
| Tags | lamer |
Introduction
| Code: |
| <html> <body> <form action="welcome.php" method="post"> Age: <input type="text" name="age" /> <input type="submit" /> </form> |
That's the HTML of it, I guess...I'm new to this so please go easy on me...That goes before the actual code.
PHP Snippet:
My first PHP
Posted on Dec 12, 2008 7:06 pm
Posted on Dec 12, 2008 7:06 pm
You should just put all the code together into the snippet. There's no reason to separate it like this. Also, always use <?php instead of <? to avoid compatibility problems with certain servers.
PHP Snippet:
My first PHP
Posted on Dec 12, 2008 9:11 pm
Posted on Dec 12, 2008 9:11 pm
Also not all servers have.... uhmmm can't think of it of the top of my head, but they won't allow $age they require you to do $age = $_POST['age'];.
Not bad for a first script :) Hope to see more, and if your stuck on a problem, yell out on the forums and we'll all help out =)
Not bad for a first script :) Hope to see more, and if your stuck on a problem, yell out on the forums and we'll all help out =)
PHP Snippet:
My first PHP
Posted on Dec 12, 2008 11:01 pm
Posted on Dec 12, 2008 11:01 pm
And also, i don't think you should put your own work down....
and
Sure its not the best script out there, but its your first PHP script. I know my first php script was
you wouldn't believe how much problems i had, firstly i had <?php hello world ?> i spent hours trying to get it to work, i ended up asking RussellReal and he told me i was missing the " and the ; but he wasn't going to tell me where.
We all start off at the same place, it doesn't matter what the quality of the script is, its worth the knowledge of what you gain from creating this script.
| Quote: |
| lol failure.... |
and
| Quote: |
| Tags lamer |
Sure its not the best script out there, but its your first PHP script. I know my first php script was
| Code: |
| <?php echo "Hello World"; ?> |
We all start off at the same place, it doesn't matter what the quality of the script is, its worth the knowledge of what you gain from creating this script.
PHP Snippet:
My first PHP
Posted on Dec 12, 2008 11:23 pm
Posted on Dec 12, 2008 11:23 pm
heh..Thanks..I'm just a pessimist, I guess.
PHP Snippet:
My first PHP
Posted on Dec 13, 2008 12:03 am
Posted on Dec 13, 2008 12:03 am
Danger, why don't you edit the snippet to reflect our suggestions?
PHP Snippet:
My first PHP
Posted on Dec 13, 2008 6:46 am
Posted on Dec 13, 2008 6:46 am
Nice to see another PHP scripter out there :L lacks a few on this site hehe.
I must be bored or something.. but this would incorporate all your HTML & PHP together;
I must be bored or something.. but this would incorporate all your HTML & PHP together;
| Code: |
| <?php echo '<html> <body>'; if (!$_POST) { echo '<form action="' .$_SERVER["PHP_SELF"]. '" method="post"> Age: <input type="text" name="age" /> <input type="submit" /> </form>'; } else { $age = $_POST["age"]; if ($age < 18) { echo 'You are too young'; } else { echo 'Welcome'; } } ?> |
PHP Snippet:
My first PHP
Posted on Dec 13, 2008 1:45 pm
Posted on Dec 13, 2008 1:45 pm
D:....I'm -trying- to code a PHP calculator of a sort, just an input field for someone to type like...2+2 and it'll return 4 when the action is submitted.
PHP Snippet:
My first PHP
Posted on Dec 13, 2008 2:14 pm
Posted on Dec 13, 2008 2:14 pm
Set a variable with the post, it should parse all symbols.. i think, never really had the need to try it out before..
PHP Snippet:
My first PHP
Posted on Dec 19, 2008 11:20 pm
Posted on Dec 19, 2008 11:20 pm
Nah, PHP won't parse symbols like that, it will just print it back to the page.
Try this instead...
Try this instead...
| Code: |
| <?php $form = "<form action=\"test.php\" method=\"post\"><input type=\"text\" value=\"\" name=\"one\"/><br/><input type=\"text\" value=\"\" name=\"two\"/><br/><input type=\"text\" value=\"\" name=\"three\"/><br/><input type=\"submit\" value=\"submit\" name=\"submit\"/></form>"; if($_POST["submit"]) { if($_POST["two"] == "+") {$value = $_POST["one"] + $_POST["three"]; echo $_POST["one"] ." + " . $_POST["three"] . " = " . $value;} elseif($_POST["two"] == "-") {$value = $_POST["one"] - $_POST["three"]; echo $_POST["one"] . " - " . $_POST["three"] . " = " . $value;} elseif($_POST["two"] == "*") {$value = $_POST["one"] * $_POST["three"]; echo $_POST["one"] . " * " . $_POST["three"] . " = " . $value;} elseif($_POST["two"] == "/") {$value = $_POST["one"] / $_POST["three"]; echo $_POST["one"] . " / " . $_POST["three"] . " = " . $value;} else echo "You have entered an unknown operator!"; } else echo stripslashes($form); ?> |
PHP Snippet:
My first PHP
Posted on Dec 20, 2008 12:00 am
Posted on Dec 20, 2008 12:00 am
or have it as a dropdown/select box for the equation? :P
PHP Snippet:
My first PHP
Posted on Jun 30, 2009 2:05 am
Posted on Jun 30, 2009 2:05 am
Hi,
I need a code that lets my customers upload a image file from their computer and then that file does 2 things
1. gets uploaded to upload folder on my server
2. a copy of that file gets e-mailed to me
this is what I have so far, any improvements/additions on this code would really be appreciated...
1.//GET IMAGE INFO
2.
3. $dir = 'images/';
4. $file_name = $_FILES['file']['name'];
5. $file_tmp = $_FILES['file']['tmp_name'];
6.
7. //CHECK FOR UPLOADED FILE
8. if(is_uploaded_file($file_tmp)){
9. //MOVE TO DIR
10. move_uploaded_file($file_tmp, $dir.$file_name);
11. }
Thanks & regards,
Lokananth
I need a code that lets my customers upload a image file from their computer and then that file does 2 things
1. gets uploaded to upload folder on my server
2. a copy of that file gets e-mailed to me
this is what I have so far, any improvements/additions on this code would really be appreciated...
1.//GET IMAGE INFO
2.
3. $dir = 'images/';
4. $file_name = $_FILES['file']['name'];
5. $file_tmp = $_FILES['file']['tmp_name'];
6.
7. //CHECK FOR UPLOADED FILE
8. if(is_uploaded_file($file_tmp)){
9. //MOVE TO DIR
10. move_uploaded_file($file_tmp, $dir.$file_name);
11. }
Thanks & regards,
Lokananth
PHP Snippet:
My first PHP
Posted on Jun 30, 2009 9:56 am
Posted on Jun 30, 2009 9:56 am
Wrong place to ask dude. Try Forums :)






