Could anyone tell me why am i having an "Undefined index" warning? I don't have any clue..
<?php
function li(){
if(isset($_POST['send'])){
$a=$_POST['encrypt'];
}echo $a;
}
?>
<select name="encrypt" size="3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
EDIT: Here is where i defined 'send'
<input type="submit" value="Send" name="send">
Here is the whole code:
<html>
<head>
</head>
<body>
</br>
<form method="post">
Text</br> <textarea name="text" rows="5" columns=40></textarea></br>
</br></br>Encrypted</br> <textarea name="en" rows="5" columns="40"><?php li(); ?></textarea></br>
<input type="submit" value="Send" name="send">
</form>
<?php
function li(){
if(isset($_POST['send'])){
$a=$_POST['encrypt'];
}echo $a;
}
?>
<select name="encrypt" size="3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</body>
</html>
I have put the select into the form section but it still doesn't work.
<html>
<head>
</head>
<body>
</br>
<form method="post" action="index.php">
Text</br> <textarea name="text" rows="5" columns=40></textarea></br>
</br></br>Encrypted</br> <textarea name="en" rows="5" columns="40"><?php li(); ?></textarea></br>
<input type="submit" value="Send" name="send">
<select name="encrypt" size="3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
<?php
function li(){
if(isset($_POST['send'])){
$a=$_POST['encrypt'];
}echo $a;
}
print_r($_POST);
?>
</body>
</html>
LAST EDIT: Everything is fine after the last change... I just needed to choose the option frome the list. I will need to protect it from this error :> Sorry, my bad
Your SELECT tag is outside FORM.. make it inside
<form method="post">
Text</br> <textarea name="text" rows="5" columns=40></textarea></br>
</br></br>Encrypted</br> <textarea name="en" rows="5" columns="40"><?php li(); ?></textarea></br>
<select name="encrypt" size="3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit" value="Send" name="send">
</form>
Please keep your dropdown for encrypt
in <form>
tag.
<form method="post">
Text</br> <textarea name="text" rows="5" columns=40></textarea></br>
</br></br>Encrypted</br> <textarea name="en" rows="5" columns="40"><?php li(); ?></textarea></br>
<select name="encrypt" size="3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit" value="Send" name="send">
</form>
<?php
function li(){
$a = '';
if(isset($_POST['send']) && isset($_POST['encrypt'])){
$a=$_POST['encrypt'];
}echo $a;
}
?>
</body>
</html>
Also check condition for $_POST['encrypt']
in function.
This Should work.You have three things to select from and no default value to fall to in case none is selected and therefore you get that error. And this should be your error:"PHP Notice: Undefined index: encrypt in... "
<html>
<head>
</head>
<body>
</br>
<form method="post" action="">
Text</br> <textarea name="text" rows="5" columns=40></textarea></br>
</br></br>Encrypted</br> <textarea name="en" rows="5" columns="40"><?php li(); ?></textarea></br>
<input type="submit" value="Send" name="send">
<select name="encrypt" size="3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
</body>
</html>
<?php
function li()
{
if(isset($_POST['send']))
{
if(isset($_POST['encrypt']))
{
$a = $_POST['encrypt'];
}
else { $a = 1;}
}
echo $a;
}
print_r($_POST);
?>