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?
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>
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>
Related
<?php
Function runSearch($name)
{
If(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "Results for " .$name;
}
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Search String: <input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit"><br>
</form>
This code is suppose to display what is entered into the Search String text box. When I don't use a function it works fine. But as soon as I place the code into the function runSearch there is no output. I'm new to php can an argument be sent to a php function and then displayed on the screen?
you need to call your function, otherwise nothing will happen. Also you need to removed the $name-parameter:
<?php
function runSearch()
{
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "Results for " .$name;
}
}
runSearch();
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Search String: <input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit"><br>
</form>
I'm working on a code which has a form. The answer on the form needs to decide to which page it should go, but it doesn't work.
<html>
<body>
<form action= "<?php echo $action; ?>" method="post">
Temperatuur: <input type="text" name="graden"><br>
<input type="Submit">
<?php
if($_GET["graden"]>=28){
$action = "Koelbox.php";
}
else{
$action = "scrabble.php";
};
?>
</form>
</body>
</html> ```
You have to declare and initialize the variable before using it.
<?php
if($_GET["graden"]>=28)
{
$action = "Koelbox.php";
}
else
{
$action = "scrabble.php";
}
?>
<form action= "<?php echo $action; ?>" method="post">
Temperatuur: <input type="text" name="graden"><br>
<input type="Submit">
</form>
First check the GET parameter, then set your $action variable accordingly and then use it in your echo.
I just initialized the variable before the form, but as far as I see the IF statement doesn't see the input in the form.
<?php
if($_GET["graden"]>=28)
{
$action = "Koelbox.php";
}
else
{
$action = "scrabble.php";
}
?>
<form action= "<?php echo $action; ?>" method="post">
Temperatuur: <input type="text" name="graden"><br>
<input type="Submit">
</form>
I try to determine if a checkbox is checked or not, but i get an error.
test.php
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Use Proxy : <input type="checkbox" name="use_proxy"><br><br>
<input type="submit">
</form>
<?php
$use_proxy = $_POST['use_proxy'];
if ($use_proxy != "on")
{
$use_proxy = "off";
}
echo "<p> use_proxy = " . $use_proxy . "</p><br>";
?>
</body>
</html>
I get this error:
Notice: Undefined index: use_proxy in C:\xampp\htdocs\mbcl\checkbox_test.php on line 11
How can i solve it?
This is the behaviour of checkbox until they are checked , they can not be fetched at backend(PHP) . You can try as below-
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Use Proxy : <input type="checkbox" name="use_proxy" value="off"><br><br>
<input type="submit">
</form>
<?php
$use_proxy = isset($_POST['use_proxy'])?"on":"off";
echo "<p> use_proxy = " . $use_proxy . "</p><br>";
?>
</body>
</html>
<?php
session_start();
?>
<form action="HardDisk.php" method="post">//form
<input type="text" name="user" />
<?php
if(isset($_POST['user']))
{
$_SESSION['userGet']=$_POST['user'];
}
?>
<input type="submit" value="submit" />
</form>
2nd page
<?php
session_start();
?>
<?php
if (isset($_SESSION['userGet'])) {
$form_value = $_SESSION['userGet'];
}
echo $form_value ;
?>
..........................................................................................................
You have used the text box name with that check the submit button name too.
<form action="HardDisk.php" method="post">//form
<input type="text" name="user" />
<input type="submit" value="submit" name="submit" />
</form>
<?php
session_start();
if(isset($_POST['submit'])&&isset($_POST['user'])) {
$_SESSION['userGet']=$_POST['user'];
}
?>
And in your second page
<?php
session_start();
if (isset($_SESSION['userGet'])) {
echo $form_value = $_SESSION['userGet'];
}
Give the submit button a name of submit then use the following PHP code:
if(isset($_POST['submit'])){
if(isset($_POST['user']))
{
$_SESSION['userGet']=$_POST['user'];
}
}
i want to do somthing like:
1.php:
<html>
<form action=1.php method=POST enctype="multipart/form-data">
Choose a user name:<input type="text" name="username">
<input type="submit" value="Save and Proceed">
</html>
<?php
if(isset($_POST['username']))
{
$name=$_POST['username'];
echo $name;
if($name=='azra')
{
?>
<html>
<form method="POST" action="1.php" enctype="multipart/form-data"></br>
enter age:</font> <input type="text" name="age">
<input type="submit" value="done">
</form>
</html>
<?php
f( isset($_POST['age']))
{
$age=$_POST['age'];
echo $age;
if($age==25)
{
echo "your age is ". $age;
echo"you are eligible";
}
}
}
}
?>
After the second form is submitted i do not want the script 1.php to run from the start but i want it to run the code following the form which is echoing the age only.
i do not want to go putting the later code in second script and accessing the variable of first script through making them session variables.please help. thankyou in advance
Change your condition to this
if ((isset($_POST['username'])) && ($_POST['submit'] == 'Save and Proceed')) {
}
this is the code i changed:
<html>
<form method="POST" action="2.php" enctype="multipart/form-data"></br>
Choose a user name:</font> <input type="text" name="username">
<input type="submit" value="Save and Proceed">
</form>
</html>
<?php
if(isset($_POST['username']) && ($_POST['submit'] == 'Save and Proceed'))
{
$name=$_POST['username'];
echo $name;
if($name=='azra')
{
?>
<html>
<form method="POST" action="2.php" enctype="multipart/form-data"></br>
enter age:</font> <input type="text" name="age">
<input type="submit" value="done">
</form>
</html>
<?php
if( isset($_POST['age']) && ($_POST['submit'] == 'done'))
{
$age=$_POST['age'];
echo $age;
if($age==25)
{
echo "your name is" .$name;
echo "your age is ". $age;
echo"you are eligible";
}
}
}
}
?>