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 attempted to search pretty thoroughly prior to asking this question (very few questions had any back story so I'm unsure if they fit or no). I am attempting to add a select field to a form in which an "if, else" function will result in a line of code being echoed IF the parameter is "yes". For the HTML, the config is as follows:
<select name="pim">
<option value="pim_enabled">Yes</option>
<option value="pim_disabled">No</option>
</select>
On my resulting configuration page, I am attempting to reference the option values and provided pim enabled is selected, additional lines of code will be echoed in which a value from a former field (TenGigED/D/D/D) will be echoed as well. My current configuration here is as such:
<?php if ($_POST["pim_enabled"]) {
echo
"Router PIM"
echo $_POST["TenGigEC/C/C/C"];
} else {
echo
"Final Config"
}
?>
I'm relatively new to this process, but I feel some degree of certainty that I'm off base with my if/else statement. Hopefully you guys can show me the error of my ways and I can build from the lesson learned.
Thanks in advance!
Your $_POST should be reading $_POST['pim']
It's value will either be "pim_enabled" or "pim_disabled", depending on the users' selection on the form.
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 last year.
I want to extract the information on this page using a script PHP Simple HTML DOM,
Here is part of the code I wrote:
$html = file_get_html('https://www.digikala.com/product/dkp-7475119/');
foreach ($html->find('p.color-900') as $e) {
$color = $e->outertext;
echo $color ;
break;
}
But unfortunately the output I receive is Undefined variable
As #Kevin Y said in his comment, you are searching for something that isn't there... yet.
Visit view-source:https://www.digikala.com/product/dkp-7475119/ and search for <p>
The page hasn't loaded the extra elements onto it yet like the <p> tag you are looking for. This is likely because the page is loading them in after-the-fact using JavaScript so you will need to find a way to get the html after the page has loaded its contents that are added in later.
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 2 years ago.
I'm having a problem with an undefined index error message in PHP. I have a form with several <select> inputs, and all of them work except for one. On one I get the undefined index error message. I don't understand why this is happening, as it is formatted exactly the same as the other <select> inputs. I've made sure that the $_POST assignment in the attached script is referencing the correct element name, and that the option values are correct in the HTML.
The code for the entire form is here: https://pastebin.com/52xtECCT
Here is the code for the <select> element:
<td>Team to Represent:</td>
<td><select name="txtTeamType" id="txtTeamType">
<?php
$resultSet = $conn->query("SELECT intTypeofTeamID, strTypeofTeam FROM TTypeofTeams");
while ($rows = $resultSet->fetch_assoc())
{
$intTypeofTeamID = $rows['intTypeofTeamID'];
$strTypeofTeam = $rows['strTypeofTeam'];
echo "<option value='$intTypeofTeamID'>$strTypeofTeam</option>";
}
?>
</select>
</td>
</tr>
And here is the code for the variable assignment. This is the code that throws the error: $intTypeofTeamID = $_POST["txtTeamType"];
Thanks for any help, I really appreciate it.
I found the solution. Changing $intTypeofTeamID = $_POST["txtTeamType"]; to
if (isset($_POST["txtTeamType"])) { $intTypeofTeamID = $_POST["txtTeamType"]; }
fixed the issue.
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 6 years ago.
I'm having difficulty assigning a PHP variable to a HTML form data.
I have assigned other text fields as variable but when I mimic this in a function it's just not playing ball...
My HTML code (only basic to start off) is:
<select id="userbrand">
<option> Option1</option>
<option> Option2</option>
<option> Option3</option>
and the corresponding PHP code is:
$camp_name = $_POST['campName'];
$broad_date = $_POST['broadDate'];
$userdomain = $_POST['userbrand'];
campName and broadDate contain the POST data from some text fields before the dropdown.
When submitting the form, I receive the following error:
Notice: Undefined index: userbrand in C:\wamp64\www\action_page.php on line 19
Is this an issue with my PHP code or my HTML?
Many Thanks in Advance
Change this
<select id="userbrand">
To this
<select id="userbrand" name="userbrand">
PHP gets the input value based on the input name, not the id.
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 6 years ago.
I have a list of profiles, and i need to make the user able to select the individual profile in a link.
I found this question and tried to follow it, but it doesnt quite work as i hoped it would: Displaying a user profile page PHP
The file to display all profiles on the page looks like this:
foreach ($rows as $row) {
echo '<a class="viewProfile" href="user.php?id=' . $r['UID']. '"><button>View Profile</button></a>';
}
But when i click the link the UID doesn't get posted in the URL, and it just looks like this: domain/user.php?id=
Update: With help from you guys i got the UID posted into the URL. Thanks!
And as jothi stated $id=$_GET['id'];
That's because $r['UID'] is not defined. You are enumerating some $row, so I assume that you mean $row['UID'].
If it doesn't work, please, post the result of this line, just before you foreach ($rows as $row)
echo print_r($rows);
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Best way to test for a variable's existence in PHP; isset() is clearly broken
(17 answers)
Closed 7 years ago.
How do the following two function calls compare to check if a variable exists for a GET call or a POST call ?
if(isset($_GET['var']))
if($_GET['var'])
Both do their job but sometimes without isset() i get a warning :
PHP Notice: Undefined index: var on at Line XX
Update
It was a $_GET not $GET. Also i know it has nothing to do with GET/POST. All i am discussing is variable check instead of HTTP method. Thanks.
$_GET[''] is usually retrieved from the browser, so if you had something like the following:
www.hello.com/index.php?var=hello
You could use:
if(isset($_GET['var'])) {
echo $_GET['var']; // would print out hello
}
Using isset() will stop the undefined index error, so if you just had www.hello.com/index.php for example then you would not see the error even though the var is not set.
Posts are usually when one page posts information to another, the method is the same but using $_POST[''] instead of $_GET['']. Example you have a form posting information:
<form method="post" action="anotherpage.php">
<label></label>
<input type="text" name="text">
</form>
In anotherpage.php to get the information would be something like:
$text = isset($_POST['text']);
echo $text; // would echo what ever you input into the text field on the other page
In a nut shell, just putting $_GET['name'] if name is not set you will get an error.
Using isset($_GET['name']) will check is the var name has any value before continuing.
Not sure if this is what you were after, but from the question this is my best guess at an answer