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;
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)
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 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.
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
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{
}