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.
php code:
1. if (isset($data['city_id']))
2. {
3. $city_id = "city_id='". $data['city_id']. "', ";
4. }
And I get:
Notice: Undefined index: city_id on line 3
How can this be?
Just ran your code sample and it works perfectly, I do not get 'undefined index' error - taking us to the big apple
<?php
$data['city_id']='New York';
if (isset($data['city_id']))
{
$city_id = "city_id='". $data['city_id']. "', ";
echo $city_id;
}
?>
output: city_id='New York',
Surely, without the $data['city_index']='New York'; I just get a blank screen, as the if condition is not met - no errors.
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 2 years ago.
any help you offer on this will be useful. Am working on my school project and this error code keeps popping up on the application "Undefined index: client_id" on line 1001"
Here is the code
public function onNewclientaddress(){
$addShipmentForm = Settings::get('addShipmentForm',true);
$data = post();
= \Spot\Shipment\Models\Address::where('user_id', $data['client_id'])->update(['default' => 0]);
if ( $addShipmentForm == "add_form_normal"){
$subitem = new \Spot\Shipment\Models\Address;
$subitem->name = htmlspecialchars($data['street_addr']);
$subitem->user_id = htmlspecialchars($data['client_id']);
$subitem->street = htmlspecialchars($data['street_addr']);
$subitem->city = htmlspecialchars($data['city_id']);
$subitem->zipcode = htmlspecialchars($data['postal_code']);
$subitem->country = htmlspecialchars($data['country_id']);
$subitem->default = 1;
$subitem->created_at = \Carbon\Carbon::now();
$subitem->updated_at = \Carbon\Carbon::now();
$subitem->save();
}
else{
line 1001 is the first line of code in the post. please pardon my English
This error indicates that $data['client_id'] is not being set. You will need to ensure that whatever form is providing this data, is passing client_id correctly.
You can see what is currently in $data with a line like:
die(var_dump($data));
This will output the data on the page.
Ensure your client_id field in your form has a name attribute:
name="client_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)
Using LIKE in bindParam for a MySQL PDO Query [duplicate]
(2 answers)
Closed 3 years ago.
Why isn't this working? I've viewed the past posts on the subject and nothing worked for me.
$sql_strongsdef_ses = "SELECT id, strongs, etym_strongs FROM ".$tablename." WHERE etym_strongs LIKE ?";
$params = array("'%".$getSearchEtymStrongs."%'");
$result_strongsdef_ses = $conn->prepare($sql_strongsdef_ses);
$result_strongsdef_ses->execute($params);
echo "<span style=\"color: red;\">".$sql_strongsdef_ses."</span><br /><br />\n";
//while ($row_ses = $result_strongsdef_ses->fetch()){
while($row_ses = $result_strongsdef_ses->fetch(PDO::FETCH_ASSOC)){
$id_ses = $row_ses['id'];
$strongs_ses = $row_ses['strongs'];
$etymstrongs_ses = $row_ses['etym_strongs'];
}
var_dump($strongs_ses);
I get the error:
Notice: Undefined variable: strongs_ses in \edit.php on line 52
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'm getting an undefined offset error
<?php
function ara($one, $two, $three)
{
#preg_match_all('/' . preg_quote($one, '/') .
'(.*?)'. preg_quote($two, '/').'/i', $three, $m);
return #$m[1];
}
$link = "example.com";
$article = file_get_contents($link);
$sport = ara('data-bin="','"',$article);
$channel = ara('data-videobin="','"',$article);
for ($i=0;$i<50;$i++)
echo"<span class='linko'><a target='_blank' href='example.org/live1.php?id=".($channel[$i]."'>$sport[$i]</a>"."<br></span>"); // error is here
?>
How can I fix it? I'am waiting for your helps. Thanks.
These codes are for a live channel website.
The channel variable has less than 50 elements.
Usually in a loop, you should set the end condition to the size of the array.
for ($i=0;$i<sizeof($channel);$i++)
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 8 years ago.
when the below code works I get the above mentioned error , what should i do ? please help me ...
<?php
//session_start();
include("dbconnect_database.php");
$tname=$_GET['tn'];
$cname=$_GET['cn'];
$des=mysql_query("desc `$tname` `$cname`");
$row=mysql_fetch_array($des);
list($type, $b) = explode('[(]',$row[1]);
list($size) = explode('[)]',$b);
?>
Try changing this:
list($type, $b) = explode('[(]',$row[1]);
to this:
list($type, $b) = explode('[(]',$row[0]);
UPDATE
The error is telling you that 1 is not a valid index for $row, so that is the problem. Just before that line, try var_dump($row). This will tell what the valid indexes for $row are, and you should be able to use that to fix your code.
there is no ' around table and column name
$des=mysql_query("desc $tname $cname");
sidenote: use mysqli_query instead of mysql because use of mysql is been deprecated
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 9 years ago.
I am trying to make a library system, everything is going well, but I faced with such a error
Notice: Undefined index: user_log in
C:\xampp\htdocs\e_library\top.php on line 23
and line 23 is here:
<?php
$user_log = $_SESSION['user_log'];
if (isset($_SESSION['user_log'])){
echo "<a href='#' style='color:#FFC'>Welcome $_SESSION[username] </a> || <a href='logout.php' style='color:#FFC'>Logout</a>";
}
else{
echo "<a href='login.php' style='color:#FFC'>Sign In</a>";
}
?>
You should put $user_log = $_SESSION['user_log']; inside your if (isset($_SESSION['user_log'])) block, instead of before.
Please check first:
if (isset($_SESSION['user_log'])){ // Because session array does not contain this yet.
//welcome message and $user_log = ..
}else{
}