This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
I have the code:
echo('
<div class="row">
<div class="col-sm-2" >
<form method="POST" action="plan.php">
<p>Selectati data raportului:<br>
<select name="SelectDR" onchange="form.submit()">
<option value="">Select...</option>
');
It is a form from which I select a value.
$option = isset($_POST['SelectDR']) ? $_POST['SelectDR'] : false;
if ($option){
$queryTXT = "SELECT * FROM ".$tabel." WHERE DataRaport='".$option."'";
...
The records of a SQLtable are filtered by the value selected from the form.
Now, what I want is to display in the url plan.php?DataRaport& variable php
I've tried to put in the form url (<form method="POST" action="plan.php?DataRaport'.$option.'">), but that doesn't show the variable.
You need GET not POST
<form method="GET">
First of all. If you want to echo this HTML every time, just use it as HTML:
<div class="row">
<div class="col-sm-2" >
<form method="POST" action="plan.php">
<p>Selectati data raportului:<br>
<select name="SelectDR" onchange="form.submit()">
<option value="">Select...</option>
</select>
</form>
<?php //your php stuff
To get the value from the URL, you need to change one thing:
<form method="POST" action="plan.php?DataReport=<?php echo $option?>">
Then you would get this variable as:
$dataReport = $_GET['DataReport'];
This would return the option value as POST and the DataReport as GET.
You can change the form method to GET if you wish, but you would then need to use $_GET to pick the selected option.
Related
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 4 years ago.
i am building a multi step login page like that of gmail,
i want the email address the the user typed in to be stored in a global variable so i can echo it in the next step of the form i have been trying but can't figure it out, have seen many error, when i change the code i get a different one the new one i have now is (Notice: Undefined index: email in C:\xampp\htdocs\xxxxx\index.php on line 3)
this is the form
<form action="" method="post" class="form-login">
<div class="step-login step-one">
<input type="text" class="email"/>
<input type="button" class="btn next-step" value="next">
</div>
</form>
this is the php code that i am trying to use and store the input, i think this is where the problem is
<?php
$emails = $_POST['email'];
if(isset($_POST['next'])){
$GLOBALS['email'] = $_GET['email'];
}
?>
this is the code where i am trying to echo the varible
<div class="data-user-find">
<p class="user-email"><?php echo $GLOBALS['email']; ?></p>
</div>
Please guys help me
The "value" of your button is "next", but your button isn't called "next", it should be <button name="next" value="next" type="submit">
Then your error would go away. Also, you define an $email variable outside of your if-clause, please put it inside your if clause, so your code would be this:
<?php if(isset($_POST["next"]) {
$email = $_POST["email"]; (DONT FORGET TO GIVE YOUR MAIL INPUT THE 'name="mail"' TAG)
$GLOBALS["email"] = $email;
} ?>
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 4 years ago.
The idea is to have list of checkbox for user to select genre type. The genre input is from database. Because the sql will return the result in an array, a for loop to get all the values and make them into a check box. The error come from third line in the loop. It show undefined index genre
<div class="list-group">
<h3>Genre</h3>
<?php
$search_genre = "SELECT DISTINCT(genre) FROM movie_db WHERE product_status ='1' ORDER BY movieid DESC"
$statement = mysqli_query($conn,$search_genre);
$result = mysqli_fetch_all($statement);
foreach ($result as $row){
?>
<div class="list-group-item checkbox">
<label><input type="checkbox" class="common_selector genre" value="<?php echo$row['genre'];?> > <?php echo $row['genre'];?></label>
</div>
<?php
}
?>
You need to give the checkbox a name, and since you are allowing multiple selections (checkbox vs radio button) you need to use a PHP array style name -
<label>
<input
name="mycheckbox[]"
type="checkbox"
class="common_selector genre"
value="<?php echo $row['genre'];?>"
<?php // here is where you could throw a check to make it pre-selected
by printing the word "checked" if a logical condition is met, etc ?>
>
<?php echo $row['genre'];?>
</label>
Now, in your processing script, you can reference $_POST['mycheckbox'] and it will contain an array with one or more values in it, one element per selected value.
for($i=0;$i<count($_POST['mycheckbox']);$i++){
print("selected value $i: ".$_POST[['mycheckbox'][$i]."\n");
}
Edit -
Just for giggles, if you wanted only one single selection (radio button) you STILL name the elements the same thing, you just leave off the PHP array brackets []
<label>
<input
name="myradio"
type="radio"
class="common_selector genre"
value="<?php echo $row['genre'];?>"
<?php /* here is where you could throw a
check to make it pre-selected
by printing the word "selected"
if a logical condition is met, etc
note in a series the last one selected
stays selected if you print selected more than once
*/
?>
>
<?php echo $row['genre'];?>
</label>
And the selected radio group value is available as $_POST['myradio']
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 4 years ago.
My Code Looks Like:
<?php
echo "
<form action='form.php'>
<input type='text' name='value'>
<input type='submit'>
</form>
";
?>
And form.php is
<?php
echo $_POST['value'];
?>
Error Code is:
Notice: Undefined index: value in C:\xampp\htdocs\dynamic\form.php on line 2
Is it possible to get the value of field created using echo command?I don't want to use database,jQuery etc.
You need to set the form method to post
<?php
echo "
<form action='form.php' method='post'>
<input type='text' name='value'>
<input type='submit'>
</form>
";
?>
you are missing method="post" in form tag
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 5 years ago.
I have a HTML form where a user fills out a few details to register for a competition. I want them to be able to upload a photo. The PHP script successfully enters everything into the database except Photo Name and Photo, any ideas why?
HTML:
<form method="post" action="addboat.php">
<p>Add your boat to the 2018 species hunt</p>
<p>Boat Name :- <input type="text" name="boatname" size="42"></p>
<p>Boat Make/Model :- <input type="text" name="boatmake" size="42"></p>
<p>Skipper :- <input type="text" name="skipper"></p>
<p>Photo:- <input type="file" name="file"></p>
<input type="hidden" name="huntyear" value="2018">
<p align="center"><input type="submit" value="Submit" name="B1"></p>
<p align="center"> </p>
</form>
PHP:
$huntyear = $_POST['huntyear'];
$boatname = $_POST['boatname'] ;
$boatmake = $_POST['boatmake'];
$skipper = $_POST['skipper'];
// Image add
$imagename=$_FILES["file"]["name"];
//Get the content of the image and then add slashes to it
$imagetmp=addslashes (file_get_contents($_FILES['file']['tmp_name']));
$query_rsCatch = "INSERT INTO SpeciesHuntBoats (Year, BoatName, BoatMake, Skipper, PhotoName, Photo) VALUES
('$huntyear','$boatname','$boatmake','$skipper','$imagename','$imagetmp')";
$rsCatch = mysql_query($query_rsCatch, $webdb) or die(mysql_error());
You should use multipart form-data in your form
<form action="action_page" method="post" enctype="multipart/form-data">
When you make a POST request, you need to encode the data that forms the body of the request HTML forms provides multipart/form-data is significantly more complicated but it allows entire files to be included in the data. enctype='multipart/form-data’ is used when you want to upload a file (images, text files etc.) to the server.
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 5 years ago.
I have a text-area, in which I need some text.
I simply need to get that text to be echoed out with PHP, while on the same page
This is my code so far:
<body>
<br>
<h1>Charles Dickens</h1>
<form action="Charles Dickens.php" method="GET">
<hr/>
<textarea rows="20" cols="100" name="textTest">This a is the text Testing area.</textarea>
<hr/>
</form>
<br>
<br>
<?php
$textTest = $_GET['textTest'];
echo $textTest;
?>
</body>
for some reason it's give me an "undefined error", though the variable is defined:
textTest is undefined.
I suggest you to change your file name as well:
it should be without space or with hyphens
here you can like this, but you need to submit a form:
<?php
if(isset($_GET["textTest"]){
echo $_GET["textTest"];
}
?>
If you don't want to submit form try it:
<script>
$('#text-id').keypress(function() {
var value = this.value;
console.log(value);
});
</script>
you have to check if the get variable is still defined:
<?php
if(isset($_GET["textTest"]){
echo $_GET["textTest"];
}
?>
or add ?textTest=the%20text to the uri ;)
I cannot add a comment for this...
Try doing
var_dump($_GET['textTest'])
Also add what Ahmad Hassan said, as before you submit the form the varible is undefined
if(isset($_GET['textTest'])) { echo $_GET['textTest'] }