0

I have a registration form with the fields

  • username
  • password
  • mobile_number
  • email

After submitting the form, the values entered by the users will be stored in the database.

Now I need to retrieve the user details from the database and export them to a Pdf file.

index.php

<form method="post" action="submit-form.php">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
  <tr>
    <td colspan="3" align="left" valign="middle" bgcolor="#008000"><div style="margin:0px 10px; font-weight:bold; color:#FFF; font-size:16px;">Simple registration form in PHP and MYSQL</div></td>
    </tr>
  <tr>
    <td colspan="3" align="left" valign="middle">
    <div id="flash"></div>
    <div id="message"></div>
    </td>
    </tr>
  <tr>
    <td width="13%" align="left" valign="middle"><strong>Userame</strong></td>
    <td width="2%" align="left" valign="middle">:</td>
    <td width="85%" align="left" valign="middle"><label>
      <input name="username" type="text" class="textbox" id="username" />
    </label></td>
  </tr>
  <tr>
    <td width="13%" align="left" valign="middle"><strong>Password</strong></td>
    <td width="2%" align="left" valign="middle">:</td>
    <td width="85%" align="left" valign="middle"><label>
      <input name="password" type="password" class="textbox" id="password" />
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle"><strong>Email</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="email" type="text" class="textbox" id="email" />
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle"><strong>Mobile No</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="mobile" type="text" class="textbox" id="mobile" />
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td align="left" valign="middle"><label>
      <input name="register" type="submit" class="submit" id="register" value="Register" />
    </label></td>
  </tr>
</table>
</form>

Submit_form.php

<div class="maindiv">
<form method="post">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
  <tr>
    <td colspan="3" align="left" valign="middle" bgcolor="#008000"><div style="margin:0px 10px; font-weight:bold; color:#FFF; font-size:16px;">Simple registration form in PHP and MYSQL</div></td>
    </tr>
  <tr>
    <td colspan="3" align="left" valign="middle">
    <div id="message"><?php
$username=$_POST['username'];
$password=$_POST['password'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];

require_once("config.php");
$query=mysql_query("INSERT INTO `registration` (`id`, `username`, `date`, `email`, `password`, `mobile`, `ip`) VALUES ('', '".$username."', '".date('d-m-Y')."', '".$email."', '".$password."', '".$mobile."', '".$_SERVER['REMOTE_ADDR']."')");
if($query)
{
    ?>
    <div style="color:#008000; font-weight:bold; text-align:center;"><h2>Registred successfully..!!</h2></div>
<?php
}else
{
?>
    <div style="color:#c24f00; font-weight:bold; text-align:center;"><h2>unable to registred !!</h2></div>
<?php
}
?></div>
    </td>
    </tr>
</table>
</form>
</div>

config.php
<?php
$a=mysql_connect("localhost","root","");
$b=mysql_select_db("database_name",$a);
?>
user3489161
  • 45
  • 3
  • 10

3 Answers3

0

You'll use a library to generate the PDF file, such as, dompdf (PHP) or jspdf (Javascript)

Here's a small example using jspdf to get you started:

<script>
var doc = new jsPDF();
doc.setFontSize(22);
doc.text(20, 20, 'This is a title');

doc.setFontSize(16);
doc.text(20, 30, 'This is some normal sized text underneath.');
</script>

Check out these two other questions already asked:

Community
  • 1
  • 1
filype
  • 8,034
  • 10
  • 40
  • 66
  • can you please share a demo file or demo link. @Filype – user3489161 May 24 '14 at 09:26
  • I want to use the php method but dompdf is very huge and difficult to understand.Is it possible with fpdf?Any other simple method available to display the data stored in database as a pdf file using php.. @Filype – user3489161 May 24 '14 at 09:35
  • Sure you can use `fpdf`. Here's some examples on dompdf https://code.google.com/p/dompdf/wiki/Usage – filype May 24 '14 at 09:37
  • Whether i need to install any resource to get this? @ Fliype – user3489161 May 24 '14 at 09:43
  • I don't understand your question. The code won't get written for you. I've pointed you at some helpful resources to get you started.. Generating a pdf file is tricky so, some understanding of PHP is required. If you have any specific question about your code, you can post code samples here and the community can help you with a specific problem. – filype May 24 '14 at 09:51
0

You can use Fpdf for the purpose.

Here is a tutorial how to creates pdf files with fpdf and php

http://www.techrepublic.com/article/generating-pdf-files-with-php-and-fpdf/

You can download the fpdf library from the official website:

http://www.fpdf.org/

fortune
  • 3,361
  • 1
  • 20
  • 30
0

I recommend to use TCPDF library. It's so easy in using. All informations you have in examples subpage

turson
  • 421
  • 2
  • 9
  • I have updated code for the registraton form.How to integrate tcpdf library in it? I can't find any example using database.. @turson – user3489161 May 24 '14 at 10:14