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 have a script that works fine for years and suddenly i face this problem :
please check the code and mend any solutionplease. any kind of help willbe appreciated.
Notice: Undefined variable: ids in /home/content/a/t/a/ataasaid1/html/category.php on line 4
Notice: Undefined variable: id in /home/content/a/t/a/ataasaid1/html/category.php on line 5
Notice: Use of undefined constant image - assumed 'image' in /home/content/a/t/a/ataasaid1/html/category.php on line 11
Notice: Use of undefined constant video - assumed 'video' in /home/content/a/t/a/ataasaid1/html/category.php on line 15
Notice: Use of undefined constant sound - assumed 'sound' in /home/content/a/t/a/ataasaid1/html/category.php on line 19
the code in file category.php is :
<?
error_reporting(E_ALL | E_STRICT);
ini_set("display_errors", 1);
$id1=$ids;
$id2=$id;
include('config.php');
$result= mysql_query("SELECT * FROM products where id like '$id1' ;");
$row=mysql_fetch_array ($result);
$type=$row['type'];
if($type==image)
{
include('categories.php');
}
else if($type==video)
{
include('categories2.php');
}
else if($type==sound)
{
include('categories3.php');
}
?>
i use the url like:
/category.php?id=64&ids=305
thank you in advanced
write like this:
if($type=="video")
else if($type=="sound")
Are you looking for
$id1=$_GET["ids"];
$id2=$_GET["id"];
or
$id1=$_POST["ids"];
$id2=$_POST["id"];
???
This error basically means that you're trying to use the variables $ids and $id, even though they do not exist. You need to define a variable before you can use it. Otherwise, you will get notices like this and your application will end up being a buggy mess. Because those two variables are not set and you are assigning them to other variables:
$id1 = $ids;
$id2 = $id;
Those variables are now useless, which means that your SQL query is also useless:
$result= mysql_query("SELECT * FROM products where id like '$id1' ;");
because $id1 isn't anything.
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)
Closed 4 years ago.
i get this php error
Notice: Undefined variable: total_earn in /var/www/..../hello.php on
line 221
But the variable works fine..
anyone can help me & have an idea ?
<?php
$con=mysqli_connect("localhost:3306","***","***","superpayment");
$a="select * from users where ref='".$req_user_info['refer']."' ";
$b=mysqli_query($con,$a);
$c=mysqli_fetch_array($b);
$mm="select * from configuration where config_name='refer_referer_points' ";
$nn=mysqli_query($con,$mm);
$oo=mysqli_fetch_array($nn);
if($c['id']>0) {
$x="select * from users where ref='".$req_user_info['refer']."' ";
$q=mysqli_query($con,$x);
$i=0;
while($res=mysqli_fetch_array($q))
{
$i++;
$x="select count(*) as ld, sum(points_used) as earn from Completed where username='".$res['username']."' ";
$y=mysqli_query($con,$x);
$z=mysqli_fetch_array($y);
$user_earn=$z['earn']/1000;
$your_earn=($user_earn*$oo['config_value'])/100;
$total_earn=$total_earn+$your_earn;
?>
The jist of it, is $total_earn is not yet initialized when you're doing $total_earn=$total_earn+$your_earn;. While PHP will automatically initialize it (As 0), it's letting you know that by not initializing it, it could be a bug in your code.
It's helpful when you may accidentally misspell a variable. See this post for more information on this.
Set it like so:
$i=0;
$total_earn=0;
while($res=mysqli_fetch_array($q))
{
$i++;
$x="select count(*) as ld, sum(points_used) as earn from Completed where username='".$res['username']."' ";
$y=mysqli_query($con,$x);
$z=mysqli_fetch_array($y);
$user_earn=$z['earn']/1000;
$your_earn=($user_earn*$oo['config_value'])/100;
$total_earn=$total_earn+$your_earn;
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 want a default value and get rid off the notice. Below is my code
<?php
$color = $_POST["color"]; //initialize variable
if (!isset($color)){ // if nothing selected set default to Blue
$color = 'Blue';
}
echo $color;
?>
So when I run the code and nothing is selected and the blue value (as it is set for default) does show up but the notice message also shows up. I want to get rid of the notice message completely. I have tried array_key_exists as well. Still can not get rid of the notice.
below is the notice I'm getting.
Notice: Undefined index: color in C:\xampp\htdocs\test3\Assignment_1_Q2.php on line 17
Thank you in advance.
Try this, First check the value with isset function.
<?php
$color = ""; //initialize variable
if(isset($_POST["color"]))
{
$color = $_POST["color"];
}
else
{
// if nothing selected set default to Blue
$color = 'Blue';
}
echo $color;
?>
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 8 years ago.
I am trying since last hour to update my database using php but unable to update.
I get the error
Notice: Undefined index: intakeid in C:\wamp\www\Multi_Edit\edit_save.php on line 3.
<?php
include('dbcon.php');
$intakeid=$_POST['intakeid'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$password=$_POST['password'];
$confirmpassword=$_POST['confirmpassword'];
$homeaddress=$_POST['homeaddress'];
$email=$_POST['email'];
$N = count($intakeid);
for($i=0; $i < $N; $i++)
{
$result = mysql_query("UPDATE registration SET firstname='$firstname[$i]',
lastname='$lastname[$i]',
password='$password[$i]',
confirmpassword='$confirmpassword[$i]',
homeaddress='$homeaddress[$i]',
email='$email[$i]'
WHERE intakeid='$intakeid[$i]`enter code here`'")or die(mysql_error());
}
error_reporting(E_ALL);
ini_set("display_errors", 5);
?>
Its always best method to check $_POST['value'] variable has value set or not using isset() function , otherwise you will get NOTICES as you have it already. check this
It happens simply there is no variable called "intakeid" in $_POST array. If you still need to get it (whereas it is set) you can do something like follows.
$intakeid=(isset($_POST['intakeid']) ? $_POST['intakeid'] : NULL ;
This will put $intakeid to null if the post variable not have the value and if it has it will put the posted value