robpal
robpal

Reputation: 834

php and get method error

I have this code :

<?php
if ($_GET["do"]=="success") {
    echo "SUCCESS";
}
?>

<form action="file.php?do=success" method="post">
<input type="text"><input type="submit">
</form>

And I get this error:

Notice: Undefined index: do in C:\Program Files\EasyPHP-5.3.8.1\www\m\file.php on line 2

What do I need to do?

Upvotes: 0

Views: 572

Answers (2)

PeeHaa
PeeHaa

Reputation: 72672

You need to check if the index exists before trying to access it:

<?php
if (isset($_GET["do"]) && $_GET["do"] == "success") {
    echo "SUCCESS";
}
?>

<form action="file.php?do=success" method="post">
<input type="text"><input type="submit">
</form>

Upvotes: 3

Scott Harwell
Scott Harwell

Reputation: 7465

Try this:

<?php
if (!empty($_GET['do']) && $_GET["do"]=="success") {
    echo "SUCCESS";
}
?>

<form action="file.php?do=success" method="get">
<input type="text"><input type="submit">
</form>

Upvotes: 1

Related Questions