Welcome to WebmasterWorld Guest from 34.204.203.142

Forum Moderators: open

Message Too Old, No Replies

database error

create pdf using fpdf17

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

New User

joined:Nov 15, 2018
posts: 6
votes: 0


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.
7:43 am on Nov 15, 2018 (gmt 0)

Preferred Member

Top Contributors Of The Month

joined:Sept 13, 2018
posts:355
votes: 71


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

The piece of code you posted, is not showing how $_SESSION['nama']; is initialized.
7:50 am on Nov 15, 2018 (gmt 0)

New User

joined:Nov 15, 2018
posts: 6
votes: 0


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...
7:59 am on Nov 15, 2018 (gmt 0)

Preferred Member

Top Contributors Of The Month

joined:Sept 13, 2018
posts:355
votes: 71


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.
8:04 am on Nov 15, 2018 (gmt 0)

New User

joined:Nov 15, 2018
posts: 6
votes: 0


nama is my data inside my table pengguna in phpmyadmin
8:06 am on Nov 15, 2018 (gmt 0)

New User

joined:Nov 15, 2018
posts: 6
votes: 0


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
2:45 pm on Nov 15, 2018 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4558
votes: 363


What is your PHP environment? What version of PHP is installed?
8:11 am on Nov 16, 2018 (gmt 0)

New User

joined:Nov 15, 2018
posts: 6
votes: 0


my php version is 5.6.31
5:47 pm on Nov 16, 2018 (gmt 0)

Preferred Member

Top Contributors Of The Month

joined:Sept 13, 2018
posts: 355
votes: 71


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.
6:45 am on Nov 21, 2018 (gmt 0)

New User

joined:Nov 15, 2018
posts: 6
votes: 0


ok i try it 1st