Jump to content

just a beginner question, pls help!!!


jesi

Recommended Posts

hi, i have just started learning php and stucked with this code thougt somebody can help me
the html code is like this


<form name="test" action="test.php" method="post">
Keyword: <input name="keyword" type="text">
<input type="submit" value="go">
</form>

and the php part for test.php was like this

[code=php:0]
<?
echo $keyword;
?>
[/code]

so when i submit the test.html should not test.php echo the word inputed in the keyword feild
Link to comment
https://forums.phpfreaks.com/topic/28656-just-a-beginner-question-pls-help/
Share on other sites

You are using the POST method
So you need to call the POST value
which in this case would be

echo $_POST["keyword"];

OR
$keyword = $_POST["keyword"];
echo $keyword;

I would suggest this

[code]
<?php
$keyword = isset($_POST["keyword"]) ? $_POST["keyword"] : "";

echo $keyword;
?>
[/code]

The line
$keyword = isset($_POST["keyword"]) ? $_POST["keyword"] : "";

Is the same as saying

if(isset($_POST["keyword"]){
$keyword = $_POST["keyword"];
}else{
$keyword = "";
}


A good start for php is

www.w3schools.com/php
[quote author=Cagecrawler link=topic=116495.msg474662#msg474662 date=1164661459]
You could just use:
[code]<?php
echo $_POST['keyword'];
?>[/code]
[/quote]

That will throw a warning if $_POST['keyword'] does not exist. Best to learn good habbits right from the get go.
[quote author=thorpe link=topic=116495.msg474666#msg474666 date=1164661650]
[quote author=Cagecrawler link=topic=116495.msg474662#msg474662 date=1164661459]
You could just use:
[code]<?php
echo $_POST['keyword'];
?>[/code]
[/quote]

That will throw a warning if $_POST['keyword'] does not exist. Best to learn good habbits right from the get go.
[/quote]

but dat one didn't worked

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.