0

I have tried to search through the forums but I am a novice and am getting more confused.

I am trying to bring an input from a form and use it as a variable in a MySql query. A shortened version of the form is -

echo "<form  method=\"get\" action=\"\">";
echo "<tr><td>Leave:</td><td><input value=\"".$_SESSION['leave']."\" class=\"text\" autocomplete=\"off\" type=\"text\" value=\"\" /></td></tr>";
echo "</form>";

I am then trying to store the input into a variable using code -

$newVar = $_GET['leave'];

However I am getting an undefined index error.

Can anyone help with this? Sorry if its a very basic problem :)

1
  • try echo '<form method="get" action="">'; Commented Mar 28, 2013 at 2:31

3 Answers 3

5

The problem is with your HTML. You need to name the input.

echo '<input name="leave" class="text" autocomplete="off" type="text" value="' . $_SESSION['leave'] . '" />';
Sign up to request clarification or add additional context in comments.

Comments

1

You declaring the "value attribute twice, you need to declare name:

echo "<form  method=\"get\" action=\"\">";
echo "<tr><td>Leave:</td><td><input name=\"".$_SESSION['leave']."\" class=\"text\" autocomplete=\"off\" type=\"text\" value=\"\" /></td></tr>";
echo "</form>";

Comments

0
echo '<form  method="get" action="">';
echo "<tr><td>Leave:</td><td><input value='{$_SESSION['leave']}' class='text' autocomplete='off' type='text' name='leave'/></td></tr>";
echo "</form>";

If you use single quotes and doubles quotes alternating, you can make your code look nicer.

For your problem, you're missing your input name:

<input type=".." name="leave" ..>

Also, notice in your output of the field, you have the value set to the session value and an empty value near the end.

value=\"\"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.