-4

I get the following error:

Undefined variable: _get in ... this is the part of the code that is causing it:

<?php
require_once("includes/config.php");
//

require('C:\xampp\htdocs\geochronology\vendor\setasign\fpdf\fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();

$search=isset($_REQUEST['search']) ? $_REQUEST['search']:'';
$option=isset($_REQUEST['option']) ? $_REQUEST['option']:'';
$period=isset($_REQUEST['period']) ? $_REQUEST['period']:'';
$datefrom=isset($_REQUEST['datefrom']) ? $_REQUEST['datefrom']:'';
$dateto=isset($_REQUEST['dateto']) ? $_REQUEST['dateto']:'';

if($period ==null){
$sql = "SELECT * FROM tblfacility JOIN tbluser on tbluser.id=tblfacility.user where ".$search." ='".$option."' ";}
else{
$sql="SELECT * FROM tblfacility JOIN tbluser on tbluser.id=tblfacility.user where ".$search." ='".$option."' AND time between '".$datefrom."' and '".$dateto."' ";
}
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{

foreach($results as $row) {
    $pdf->SetFont('Arial','',12);   
    $pdf->Ln();
    foreach($row as $column)
        $pdf->Cell(40,10,$column,1);
} }
$pdf->Output();
?>

It is giving a blank output.FIle problem may be with variable option and search .

  • 1
    Does this answer your question? [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Dharman Nov 13 '19 at 09:51
  • That code looks pretty bad - have you defined all these constants you are accessing? – Nico Haase Nov 13 '19 at 09:52
  • If an answer solved your question and you get a new error, you should not change the content of your question. – Adam Nov 13 '19 at 10:52

2 Answers2

3

The global variable $_GET is only in uppercase. So you have to change

$search=$_get[search];

to

$search=$_GET['search'];
Adam
  • 25,960
  • 22
  • 158
  • 247
  • iT is not working still the error Warning: Use of undefined constant search - assumed 'search' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\geochronology\library\admin\genratepdf.php on line 23 Notice: Undefined index: search in C:\xampp\htdocs\geochronology\library\admin\genratepdf.php on line 23 –  Nov 13 '19 at 09:33
  • 2
    @dev yes you have to put `search` in quotes. Like this: `'search' ` – Adam Nov 13 '19 at 09:35
  • 1
    @dev same for the other key that you use in `$_POST` – Adam Nov 13 '19 at 09:36
  • still it shows error Notice: Undefined index: search in C:\xampp\htdocs\geochronology\library\admin\genratepdf.php on line 23 –  Nov 13 '19 at 09:38
  • Have u changed that code.I am new to this forum Just asking –  Nov 13 '19 at 09:43
  • @dev @dev maybe its better if you search for a basic tutorial how to handle post get variables with php, or google the error messages itself. `Undefined index: search in ...` means that there was no input with name `search` send by the get request. Yes I changed the code because it was unrelated to the error message. Your question is about basic GET request in PHP and its not relevant that you are using FPDF. If you ask questions here in future, please make sure to provide a minimal example instead of large pieces of code that are unrelated. – Adam Nov 13 '19 at 09:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/202256/discussion-between-dev-and-adam). –  Nov 13 '19 at 09:45
1

Try this one,

$search=isset($_GET['search']) ? $_GET['search']:'';

or

$search=isset($_REQUEST['search']) ? $_REQUEST['search']:'';
selvan
  • 1,183
  • 3
  • 16
  • 24
  • We now have the null-coalescing operator. There is no need for this. – Dharman Nov 13 '19 at 09:51
  • Can you add more information to your answer? How does it solve the given error? Please note that the error message was not about any undefined indices within an array – Nico Haase Nov 13 '19 at 09:53
  • @NicoHaase this solution could not solve the problem.Please help –  Nov 13 '19 at 09:55
  • @NicoHaase Is there any way to transfer the variable to the third page –  Nov 13 '19 at 10:01
  • What do you mean by that? There is no "third page" in your question. And if you have additional details about the problem, please edit your question to contain all information. Don't put such stuff in the comment section – Nico Haase Nov 13 '19 at 10:04
  • @selvan It gives a blank page output –  Nov 13 '19 at 10:09
  • add the below two lines in the top of the page. error_reporting(E_ALL^E_STRICT); ini_set("display_errors","on"); – selvan Nov 13 '19 at 10:21
  • @selvan nothing happened –  Nov 13 '19 at 10:24
  • @selvan Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file in C:\xampp\htdocs\geochronology\vendor\setasign\fpdf\fpdf.php:271 Stack trace: #0 C:\xampp\htdocs\geochronology\vendor\setasign\fpdf\fpdf.php(1063): FPDF->Error('Some data has a...') #1 C:\xampp\htdocs\geochronology\vendor\setasign\fpdf\fpdf.php(999): FPDF->_checkoutput() #2 C:\xampp\htdocs\geochronology\library\admin\genratepdf.php(53): FPDF->Output() #3 {main} thrown in C:\xampp\htdocs\geochronology\vendor\setasign\fpdf\fpdf.php on line 271 –  Nov 13 '19 at 10:27
  • Please remove If any unwanted white space or html content in the page. So that the header will load the pdf document. – selvan Nov 13 '19 at 10:35