Killersites.com Homepage Welcome Guest   |   Register  |  Login
Login Name Password
  Search  
  Index  | Recent Threads  | Unanswered Threads  | Who's Online  | User List  | Help



Quick Go »

No member browsing this thread
Thread Status: Active
Total posts in this thread: 19
Posts: 19   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 5174 times and has 18 replies Next Thread
Male badboy1245
Stranger




Joined: Dec 11, 2008
Post Count: 11
Status: Offline
Reply to this Post  Reply with Quote 
using the $_POST

<html>
<head>
<title>Form</title>
<body>
Name: <input type="text" name="name" />
Age:
<input type="text" name="age" />
<input type="submit" value="send" />


Welcome <?php
echo $_POST(["name"]);
?>.<br />
You are <?php
echo $_POST["age"]
?> years old.

</form>
</body>
</html>


i'm trying to get the $_post to work but i can't for some reason...every time i try the run the code with $_post i get an err message....can some one tell why it wont run on my computer or my server....everything works good i just can't get it to print anyhting on my page

[Dec 11, 2008 2:16:00 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male falkencreative
Advanced Member
Member's Avatar

USA
Joined: Aug 14, 2007
Post Count: 1129
Status: Offline
Reply to this Post  Reply with Quote 
Re: using the $_POST

$_POST assumes that your form has been submitted. I think this is what you were attempting to do:

-- missing a closing head tag
-- missing an opening form tag
-- minor reformatting

Basically, what this does is use a PHP snippet to check if the form has been submitted. If it has, it grabs the form values and displays the welcome message. If not, the form gets displayed.


<html>
<head>
<title>Form</title>
</head>
<body>

<?php

if (isset($_POST['submit'])) {
$name = $_POST['name'];
$age = $_POST['age'];

echo "Welcome $name.<br/>You are $age years old.";
}
else { ?>

<form action="" method="post">
<div>
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />

<input type="submit" value="send" name="submit" />
</div>
</form>

<? } ?>

</body>
</html>

----------------------------------------
Benjamin Falk | student : designer : developer
Twitter: falkencreative
[Dec 11, 2008 2:27:03 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male badboy1245
Stranger




Joined: Dec 11, 2008
Post Count: 11
Status: Offline
Reply to this Post  Reply with Quote 
Re: using the $_POST

<html>
<head>
<title>Form</title>
<body>

<?php

if($_GET["action"] == 'send'){

echo ('Data = '(.$_GET['keyword']));

}
?>
<form method="get" action="index.php"


<fieldset>
<legend>Form Data</legend>

<p>
<label for="keyword">Search keyword:</label>
<input type="text" name="keyword" size="25" />
</p>

<p>
<input type="submit" name="action" value="send" />
</p>

</fieldset>

</font>
</body>
</html>


I keep getting an err with post and echo....can some one tell why i'm getting that err.....thanks......
[Dec 11, 2008 5:45:55 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male falkencreative
Advanced Member
Member's Avatar

USA
Joined: Aug 14, 2007
Post Count: 1129
Status: Offline
Reply to this Post  Reply with Quote 
Re: using the $_POST

-- unnecessary parenthesis in your echo statement
-- no closing ">" on your opening form tag
-- extra unneccessary "</font>" tag (don't use <font> use CSS)
-- use isset() to check if the form has been submitted... otherwise, you'll get an error since PHP is checking a variable that doesn't exist yet

Corrected code:

<html>
<head>
<title>Form</title>
<body>

<?php

if(isset($_GET["action"])){

echo 'Data = ' . $_GET['keyword'];

}
?>

<form method="get" action="index.php">


<fieldset>
<legend>Form Data</legend>

<p>
<label for="keyword">Search keyword:</label>
<input type="text" name="keyword" size="25" />
</p>

<p>
<input type="submit" name="action" value="send" />
</p>
</fieldset>

</body>
</html>

----------------------------------------
Benjamin Falk | student : designer : developer
Twitter: falkencreative
[Dec 11, 2008 6:24:25 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male badboy1245
Stranger




Joined: Dec 11, 2008
Post Count: 11
Status: Offline
Reply to this Post  Reply with Quote 
Re: using the $_POST

How come my fieldset falls down when i click on send the echo doest work?
[Dec 11, 2008 11:05:34 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male falkencreative
Advanced Member
Member's Avatar

USA
Joined: Aug 14, 2007
Post Count: 1129
Status: Offline
Reply to this Post  Reply with Quote 
Re: using the $_POST

How come my fieldset falls down when i click on send the echo doest work?


You are going to have to rephrase your question. It doesn't seem to make much sense. I did test my code above and I know it works correctly.
----------------------------------------
Benjamin Falk | student : designer : developer
Twitter: falkencreative
[Dec 11, 2008 11:23:43 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male badboy1245
Stranger




Joined: Dec 11, 2008
Post Count: 11
Status: Offline
Reply to this Post  Reply with Quote 
Re: using the $_POST

what editor are you using....maybe if i use the same editor it will work or could have something to do with my configuration....i'm using php expert editor 4.0......it has its on server could it be that i'm not configuring it right
[Dec 12, 2008 11:42:17 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male falkencreative
Advanced Member
Member's Avatar

USA
Joined: Aug 14, 2007
Post Count: 1129
Status: Offline
Reply to this Post  Reply with Quote 
Re: using the $_POST

what editor are you using....maybe if i use the same editor it will work or could have something to do with my configuration....i'm using php expert editor 4.0......it has its on server could it be that i'm not configuring it right


What text editor you are using doesn't matter, it's all working with the same code. I am using Textmate on my mac / Notepad++ on a PC. Also, this is very basic script, so you shouldn't need to adjust any server settings.

Just to be clear, here is what it currently does for me:

-- I open the page. The form displays, with an input that asks what search keyword I want
-- I enter something, "test" in this case, and press "send"
-- The page refreshes, and I then get the text "Data = test" at the top of a page, followed by the form.

If that isn't what you were intending, you'll need to explain what you were expecting the code to do. It is working correctly, and I have tested it on two machines. If you are still getting some sort of error, you'll need to explain clearly what issue you are running into.
----------------------------------------
Benjamin Falk | student : designer : developer
Twitter: falkencreative
[Dec 12, 2008 11:51:56 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male badboy1245
Stranger




Joined: Dec 11, 2008
Post Count: 11
Status: Offline
Reply to this Post  Reply with Quote 
Re: using the $_POST

its running for me and i'm get the the text box and everyting but when i type something into the box and press send the page refreshes and i get the same screen as it did when i run it....it doesnt show me the "Data= " and text that i type into it
[Dec 12, 2008 12:16:32 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male falkencreative
Advanced Member
Member's Avatar

USA
Joined: Aug 14, 2007
Post Count: 1129
Status: Offline
Reply to this Post  Reply with Quote 
Re: using the $_POST

OK, a couple questions then...

-- Do you have a server running (you know you have to have a server to display .PHP files correctly, right?). Either you'll need to upload your files to your hosting and view them in your browser, or you'll need to use something like WAMP (http://www.wampserver.com/en/ -- PC) or MAMP (http://www.mamp.info/en/index.php -- for mac).

-- If you are using a server on your local machine, are you actually viewing your files on the server (your URL in the browser should be something like: http://localhost/) or are you just accessing the file directly (the URL in your browser will start with file:///C... etc). If you are trying to access the file directly, it won't work. It needs to be run through localhost.
----------------------------------------
Benjamin Falk | student : designer : developer
Twitter: falkencreative
----------------------------------------
[Edit 1 times, last edit by falkencreative at Dec 12, 2008 12:25:14 PM]
[Dec 12, 2008 12:20:14 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Posts: 19   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread