mysql_connect('localhost','root','');
mysql_select_db('db_enrollment');

<?php
require('fpdf.php');

class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
//$this->Image('logo.jpg',22,10,160);
// Arial bold 15
$this->SetFont('Arial','B',15);
// Move to the right
$this->Cell(80);

// Line break
$this->Ln(20);

}

$result=mysql_query("select * from omr_result");




// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);

}
}

$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->Output();



?>

i have a code to export mysql table as a pdf but there is a error in line 24

Recommended Answers

All 3 Replies

Member Avatar for LastMitch

@biddut.hossain.75

i have a code to export mysql table as a pdf but there is a error in line 24

Read this

http://php.net/manual/en/function.mysql-query.php

mysql_query() function doesn't work anymore you need to used either

mysqli_query()
PDO::query()

Try to used this function:

From this:

$result=mysql_query("select * from omr_result");

To this:

$result=mysqli_query("select * from omr_result");

Test the query to see whether you are connected to the database.

Your problem is on this line:

$result=mysql_query("select * from omr_result");

You cannot declare, or, set variables inside the class this way. You shoud consider trying to implement this inside a function:

public function query()
{
    $connect = mysql_query("SELECT * FROM something");

}
Member Avatar for diafol
mysql_connect('localhost','root','');
mysql_select_db('db_enrollment');
<?php
require('fpdf.php');

should be

<?php
mysql_connect('localhost','root','');
mysql_select_db('db_enrollment');
require('fpdf.php');

mysql_* can't be used if you don't have a connection. Your code shows mysql_connect and mysql_select_db outside the php tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.