Steven Matthews
Steven Matthews

Reputation: 11355

How to convert a HTML Form Variable Passed to a PHP Script as a String?

So I have this HTML:

<form action="tickeroutput.php">Ticker Symbol: <input type="text" name="ticker" method="get"/>
                <input type="submit" value="Submit" />
            </form>

And then I want to use the data contained in ticker, however I have this in tickeroutput.php, and it doesn't seem to want to work:

    $ticker = $_GET("ticker");

Is this not the correct format to have $ticker as a string? I specifically need what the user inputs as a string variable.

Upvotes: 0

Views: 1103

Answers (2)

ahoura
ahoura

Reputation: 689

First of all I think you meant to write :

<form action="tickeroutput.php" method="get">Ticker Symbol: 
<input type="text" name="ticker"/>
                <input type="submit" value="Submit" />
            </form>

and to fix your problem you should replace $ticker = $_GET("ticker"); with $ticker = $_GET["ticker"]; replace () with []

Upvotes: 2

Brian Glaz
Brian Glaz

Reputation: 15696

You need to use square brackets, not (). $ticker = $_GET['ticker'] $_GET is an array.

Upvotes: 1

Related Questions