I am trying to generate identity card through fpdf
after accepting details through html form
element. The student is required to submit his/her photo by selecting a file. The details are processed in a php file where fpdf
library is used to generate the pdf.
The problem is that after selecting the image file it seems only the name is forwarded to the php file. How can I output the image from the php
file int o the pdf?
Here is my html form element
<form action="action.php" >
<fieldset id="myform">
<legend><h4>Student Registration Form</h4></legend>
<label for="name">Name: </label>
<input type="text" name="name" id="name" required><br><br>
<label for="gender">Gender: </label>
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female <br><br>
<label for"enrol">Enrolment number: </label>
<input type="text" name="enrol" id="enrol" required>
<br><br>
<label for"dept">Department: </label>
<select name="dept" id="dept" placeholder="choose" required>
<option value="" disabled selected>Select your option</option>
<option value="CSE">CSE</option>
<option value="met">Metallurgy</option>
<option value="it">Information Technology</option>
<option value="aero">Aerospace</option>
<option value="me">Mechanical</option>
<option value="etc">Electronics and Telecommunication</option>
<option value="ee">Electrical</option>
<option value="civil">Civil</option>
<option value="mining">Mining</option>
</select>
<br><br>
<label for"from">From: </label>
<input type="month" name="from" id="from" size="6" required>
<label for="to">To: </label>
<input type="month" name="to" id="to" size="6" required>
<br><br>
<label for"address" id="addr" >Address: </label>
<textarea rows="10" cols="50" name="address" id="address" placeholder="Enter your address here" required></textarea>
<br><br>
<label for="studentimg">Select image: </label>
<input type="file" id="img" name="studentimg" >
<br><br>
<input type="submit" id="btn">
</fieldset>
</form>
Here is my php program:
<?php
$name=$_GET['name'];
$enrol=$_GET['enrol'];
$dept=$_GET['dept'];
$from=$_GET['from'];
$to=$_GET['to'];
$address=$_GET['address'];
$img=$_GET['studentimg'];
$gender=$_GET['gender'];
$link=mysqli_connect('localhost','serve17','serve17','serve17')
or die("Error connecting to database");
$query="insert into students_g3 (enrol,name,gender,dept,start,end,address,img) values ('$enrol','$name','$gender','$dept','$from','$to','$address','$img') ";
if($result=mysqli_query($link,$query))
{
//echo "Added";
}
else
{
//echo "Error: ". mysqli_error();
}
require ('fpdf181/fpdf.php');
$pdf=new FPDF('L','mm',array(90,70));
$pdf->AddPage();
$pdf->Rect(2,2,86,66,'D');
$pdf->Image('index.jpeg',7,5,20,15);
$pdf->Cell(25,3);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(57,5,"ID CARD");
$pdf->Line(2,22,88,22);
$pdf->Ln(14);
$pdf->SetFont('Arial','B',7);
$pdf->Cell(10,4,
"NAME: ".$name);
$pdf->Ln(4);
$pdf->Cell(10,4,
"College ID: ".$enrol);
$pdf->Ln(4);
$pdf->Cell(10,4,
"Department: ".$dept);
$pdf->Ln(4);
$pdf->Cell(10,4,
"Session: ");
$pdf->Ln(4);
$pdf->Cell(10,4,
"From: ".$from);
$pdf->Ln(4);
$pdf->Cell(10,4,
"TO: ".$to);
$pdf->Output();
?
If any other information is required drop a comment below.