Forum Moderators: open

Message Too Old, No Replies

database error

create pdf using fpdf17

         

fadli93

5:46 am on Nov 15, 2018 (gmt 0)

5+ Year Member



hye i wanna create a pdf in php and i got an error, it shows:
Notice: Undefined index: nama in C:\xampp2\htdocs\qurban\pdf.php on line 3

Notice: Undefined index: nama in C:\xampp2\htdocs\qurban\pdf.php on line 8

here is my code:
<?php
session_start();
$nama =$_SESSION['nama'];
require('fpdf17/fpdf.php');

$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("qurban", $connection);
$query = mysql_query("select * from pengguna where nama='$_SESSION[nama]'", $connection);

while($rows=mysql_fetch_array($query))
{
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
i'm already change every data inside the table but the result remain same.

justpassing

7:43 am on Nov 15, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



It's jut that this is not set:
$_SESSION['nama'];

The piece of code you posted, is not showing how $_SESSION['nama']; is initialized.

fadli93

7:50 am on Nov 15, 2018 (gmt 0)

5+ Year Member



how to set it? this is my full code:

<?php
session_start();
$nama =$_SESSION['nama'];
require('fpdf17/fpdf.php');

$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("qurban", $connection);
$query = mysql_query("select * from pengguna where nama='$_SESSION[nama]'", $connection);

while($rows=mysql_fetch_array($query))
{

//A4 width : 219mm
//default margin : 10mm each side
//writable horizontal : 219-(10*2)=189mm

$pdf = new FPDF('P','mm','A4');

$pdf->AddPage();


//set font to arial, bold, 14pt
$pdf->SetFont('Arial','B',14);

$pdf->Cell(189,5,'',0,1);//end of line
$pdf->Cell(189,5,'',0,1);//end of line
//Cell(width , height , text , border , end line , [align] )

$pdf->Cell(140,5,'YAYASAN SALAM MALAYSIA',0,0);
$pdf->Cell(69,5,'INVOICE',0,1);//end of line

$pdf->Cell(189,5,'',0,1);//end of line
$pdf->SetFont('Arial','',12);

$pdf->Cell(140,5,'',0,0);
$pdf->Cell(30,5,'No. Rujukan',0,0);
$pdf->Cell(19,5,$rows['id_pengguna'],0,0);
//make a dummy empty cell as a vertical spacer
$pdf->Cell(189,5,'',0,1);//end of line



$pdf->SetFont('Arial','B',12);
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(90,5,'Pegawai,',0,1);
$pdf->SetFont('Arial','',12);
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(90,5,'No 22 Jalan Changgai,Pjs9,',0,1);
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(90,5,'46000,',0,1);
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(90,5,'Petaling Jaya,',0,1);
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(90,5,'Selangor.',0,1);
$pdf->Cell(189,5,'',0,1);
//billing address
$pdf->SetFont('Arial','B',12);
$pdf->Cell(100,5,'Bill Kepada',0,1);//end of line

$pdf->Cell(189,5,'',0,1);//end of line
$pdf->SetFont('Arial','B',12);

//add dummy cell at beginning of each line for indentation
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(90,5,$rows['nama'],0,1);

$pdf->SetFont('Arial','',12);

$pdf->Cell(10,5,'',0,0);
$pdf->Cell(90,5,$rows['alamat'],0,1);
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(90,5,$rows['poskod'],0,1);
$pdf->Cell(10,5,'',0,0);
//$pdf->Cell(90,5,$rows['bandar'],0,1);
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(90,5,$rows['negeri'],0,1);


//make a dummy empty cell as a vertical spacer
$pdf->Cell(189,10,'',0,1);//end of line



$pdf->Cell(138,5,'',0,1);

//invoice contents


$pdf->SetFont('Arial','',12);


$pdf->Cell(189,10,'',0,1);
$pdf->SetFont('Arial','',12);
$pdf->Cell(175,10,'*Sila bawa invoice sebagai bukti tempahan',0,1);
$pdf->Cell(175,10,'*Sebarang masalah atau cadangan sila isi borang aduan di Laman Hubungi Kami ',0,1);
$pdf->Output();
}?>

if i delete the database, pdf will come out...

justpassing

7:59 am on Nov 15, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



how to set it? this is my full code:

This is your code, you are supposed to know what is this "nama", that you are storing in the user's session.

fadli93

8:04 am on Nov 15, 2018 (gmt 0)

5+ Year Member



nama is my data inside my table pengguna in phpmyadmin

fadli93

8:06 am on Nov 15, 2018 (gmt 0)

5+ Year Member



oh ya btw after i code $query = mysql_query("select * from pengguna where nama=$_SESSION['nama']", $connection);

it shows: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in

not2easy

2:45 pm on Nov 15, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What is your PHP environment? What version of PHP is installed?

fadli93

8:11 am on Nov 16, 2018 (gmt 0)

5+ Year Member



my php version is 5.6.31

justpassing

5:47 pm on Nov 16, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



nama is my data inside my table pengguna in phpmyadmin

Yes, but when you do
$nama =$_SESSION['nama']; 

It means that earlier you had
$_SESSION['nama']=...

The error you are seeing is being you are retrieving the value of $_SESSION['nama'], whereas it has never been set before.
my php version is 5.6.31

You need to switch to the PHP 7.2, because the 5.6 branch reaches its end of life on December 31th 2018, no more security support after this date.

fadli93

6:45 am on Nov 21, 2018 (gmt 0)

5+ Year Member



ok i try it 1st