i'm trying a simple facebook application, running on localhost using wamp 2.0 , i got the date using the following code as shown here, when i run echo($bd); i get the correct result but when the following code runs i get an error.
Code
$bd = $fbme['birthday'];
$datearr = "0";$month = "0"; $date = "0"; $year = "0";
$datearr = explode('-', $bd);
list($month,$date,$year) = $datearr;
echo($month);
Error :
Notice: Undefined offset: 2 in C:\wamp......\index.php on line 30
Notice: Undefined offset: 1 in C:\wamp.....\index.php on line 30
Could you please suggest the reason and why this is occuring, any way how to get rid of this. Thanks a lot!!
The string stored in $fbme['birthday'] does not contain any '-' chars. Most likely it is empty. Check where $fbme is populated and an actual birthday is present.
Related
I'm converting dates (Gregorian to Islamic Hijri). PHP 7 is displaying a "non-numeric" warning error. How can I amend the code?
This is for a Linux server running PHP 7.2 and Apache. It worked as expected with PHP 5! Have tried suggestions on stackoverflow, e.g. (intval) + (int), to no avail!
1510 $date = "25/1/1999";
1511 $Gdate = explode ('/', $date) ;
1512 $day = $Gdate[0];
1513 $month = $Gdate[1];
1514 $year = $Gdate[2];
1515
1516 $jgc=0;
1517 $m=$month;
1518 $y=$year;
1519 if($m<3)
1520 {
1521 $m=$m+12;
1522 $y=$y-1;
1523 }
1524 $c=floor($y/100.);
1525
1526 if($y==1582 && $m>10) {$jgc=10;}
1527 if($y>1582) {$jgc=2-$c+floor($c/4.);}
1528
1529 $jd= floor(365.25*($y+4716))+floor(30.6001*($m+1))+$day+$jgc-1524;
I expect it to simply work and not produce the following error:
Warning: A non-numeric value encountered in process.php on line 1529
Trying this code on php 7.2.4 works without error so I think its something on your specific php.
Try to convert to integer your variables before make calculatings
$date = "25/1/1999";
$Gdate = explode ('/', $date) ;
$day = (int)$Gdate[0];
$month = (int)$Gdate[1];
$year = (int)$Gdate[2];
$jgc=0;
$m=$month;
$y=$year;
if($m<3)
{
$m=$m+12;
$y=$y-1;
}
$c=floor($y/100.);
if($y==1582 && $m>10) {$jgc=10;}
if($y>1582) {$jgc=2-$c+floor($c/4.);}
$jd= floor(365.25*($y+4716))+floor(30.6001*($m+1))+$day+$jgc-1524;
echo $jd;
The problem says, you have a non numeric value.Then, I think your date is malformed. I suggest you use DateTime() library for correct parsing dates.
I have this code which is showing this error in the logs. Any ideas why?
PHP Notice: Undefined offset: 1
$microtime = microtime(true);
list($time,$mili) = explode(".", $microtime);
EDIT:
Sorry forgot to mention that this error doesn't happen every time, I just noticed it in the logs. Maybe it only happens when there are no milliseconds
Example output of microtime: 1418114280.8363
A bit too long for a comment, but (as an alternative) try using
$microtime = microtime(true);
$time = floor($microtime);
$mili = fmod($microtime, 1);
and see what result this gives
It works fine check it
echo $microtime = microtime(true);
print_r(explode(".", $microtime));
list($time,$mili) = explode(".", $microtime);
print_r($time);
echo '---';
print_r($mili);
Good day again guys. APOSTROPHES gettin on my nerve. Please Help guys! I get this error when the RESPO column have an APOSTRPHE word on it "OFFICE'S".
Notice: Undefined offset: 1 in xxx:\xxxx\www\ptoms2\reports\view_reports.php on line 14
Notice: Undefined offset: 1 in xxx:\xxxx\www\ptoms2\reports\view_reports.php on line 15
My line 14 and 15 are this codes which this makes the error lines:
$month = date("m", strtotime($data[1]));
$year = date("Y", strtotime($data[1]));
To sum up all my view_reports.php are this following:
<?php
$respo = $_GET['respo'];
$data = explode("+", ($respo));
$month = date("m", strtotime($data[1]));
$year = date("Y", strtotime($data[1]));
$viewrecord = "SELECT dv.*, dv.respo, (pr.pr_gsis_c + pr.pr_gsis_l) AS deduction FROM tbl_dv dv LEFT OUTER JOIN tbl_payroll pr on dv.dv_id = pr.dv_id LEFT OUTER JOIN tbl_payroll tpr on tpr.dv_id = dv.dv_id WHERE dv.respo='".mysql_real_escape_string($data[0])."' && year(dv.date_added)=$year && month(dv.date_added)=$month ";
$run_viewrecord = mysql_query($viewrecord) or die(mysql_error());
{
etc....
THank you in advance. I gettin this error for a week and so.. I never imagine that just this APOSTROPHES making this error.. Please Help!
EDIT: This is the actual code I have.. I tried to inject mysql_real_escape_string maybe this is the solution of most APOSTROPHES error. But nothin is working..
This is a DROPDOWN Generated report. In the report.php I choose a RESPO and will gather all RESPO respectively upon the month I selected too.. BUT I have a RESPO that is PROV'L BUDGET OFFICE. WHich the PROV'L contains a APOSTROPHE.. WHEN I Generate the report according to this RESPON I got that error.. and the address is like this:
http://xxxxx/xxxxxx/reports/view_reports.php?respo=PROV
it should be like this sample without apostrophe:
http://xxxxx/xxxxx/reports/view_reports.php?respo=BIPC%2B2014-02-04+10%3A53%3A04
You need to use urlencode / decode on the $_GET value passed so it will not truncate the information after the apostrophe. That will resolve your problem.
You would use decode on the code posted above like so:
$respo = urldecode($_GET['respo']);
The code you are preparing this statement from would be:
$variable = urlencode($row['somethinghere']
Now if it contains an apostrophe it would still send the entire string of data just fine.
I'm having this problem where my PHP code is concatenating instead of adding
$offset=$_POST['offset']; //Get the offset
$searchLimit = 10;
$searchCount = count(sql) //For the purpose of this question, it returns the result count
Now I want to calculate the 'from' display for pagination, so I do
$from = ($offset*$searchLimit)+1;
It works fine when
$offset == 0
I get the expected result which is 1. But when
$offset == 1
It gives me 101. Basically it is concatenating the 10 and 1 to give me 101. I've tried the following
$from = (int)($offset*$searchLimit)+1
$from = ((int)($offset)*$searchLimit)+1
$from = (((int)($offset)*$searchLimit)+1)
I even tried
$offset = (int)$_POST['offset'];
But all of them are giving the same result.
You are missing a $ before searchLimit. As a result, it is being treated as a string. This result in unexpected behaviour.
You missed a $ sign before searchLimit (and perhaps before sql). -_-
I've a php file in which I've codes like
$xml_time = $update->$node->timestamp; **//Case 1**
$time = date("c",$xml_time);
$normal_time = time(); **//Case 2**
$time = date("c",$normal_time );
The variable $xml_time is retrieved from an external xml file using simpleXML. The time is stored using the time() function at some earlier point.
The problem is that, when I call the line $time = date("c",$xml_time); (is Case 1), I get an error message saying <b>Warning</b>: date() expects parameter 2 to be long, object given in <b>C:\xampp\blah\blah\blah\ajax.php</b> on line <b>46</b><br /> but in Case 2, no error shows up.
Can anyone help me identify the problem??
try if this works:
$xml_time = (integer) $update->$node->timestamp; **//Case 1**
$time = date("c",$xml_time);
This will typecast SimpleXML object to integer.