Reputation: 75
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
Upvotes: 1
Views: 307
Reputation: 783
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.
Upvotes: 1