MPDF Checkbox not showing in PDF only dot - php

Im using MPDF to output my html form into a PDF. But my problem is, when it converts to PDF the box shape of checkbox is gone, below is the sample how i coded the checkbox
<input type='checkbox' name='opening' value='referal' checked="checked"> Check 1
<input type='checkbox' name='opening' value='referal2' checked="checked"> Check 2
Here's the html output before converting:
Here's the html output before converting:
Here's the mpdf OUTPUT:
Here's the mpdf output:
As you can see, the check '✓' became dot '.' and the box shape is gone.
Is there something wrong with my code? Or It is just not possible with MPDF?
But let me add, if I'm using radio button, all is fine. But what I need is checkbox not radio button.
Radio Button OUTPUT:Radio Button
Heres my full code GeneratePDF.php
<?php
include('mpdf60/mpdf.php');
$html .=
"
<!DOCTYPE html>
<html>
<head>
<title>Applicant Information Sheet</title>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<link rel='stylesheet' type='text/css' href='style.css'>
</head>
<body>
<div class=' header-logos text-center'>
<img src='headerimage/logo1.png' width='270' height='90' class=''>
<img src='headerimage/logo2.png' width='170' height='130' class='' >
<img src='headerimage/logo3.png' width='180' height='90' class=''>
</div>
<div class='container top-head'>
<p class='form-hrm'>FORM-HRM-R-003</p>
<hr>
<div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>
<div class='profile-pic'></div>
<p class='blackened-head'>APPLICANTS INFORMATION SHEET</p>
<form class='head-form'>
<span class='detail1'>Date</span><span class='user-texts'>:</span><span class='user-texts bold'> Nicky Jacobo</span><br>
<span class='detail2'>Position</span><span class='user-texts'>:</span> <span class='choice1 '>1st choice</span><span class='user-texts'>:</span> <span class='user-texts bold'>Information Technology</span><span class='choice2'> 2nd choice</span><span class='user-texts'>: </span><span class='user-texts bold'>Hotel Management</span><br>
<span class='detail3'>Salary Expectation</span><span class='user-texts'>:</span><span class='user-texts bold'>100,000</span><br>
<span class='detail4'>Availability to Start</span><span class='user-texts'>: </span><span class='user-texts bold'>Anytime</span><br>
</form>
<p class='blackened peros'>PERSONAL INFORMATION</p>
</div>
</div><!-- End of top-head -->
<!--==========================================
PERSONAL INFORMATION
============================================= -->
<div class='container personal-information'>
<table>
<tr class='zero-row'>
<th colspan='6' >NAME: <span class='outs'>
<span class='lastname ' style='font-weight: 900;'>JACOBO</span>
<span class='firstname' style='font-weight: 900;'>NICKY</span>
<span class='midname' style='font-weight: 800;'>CABALU</span>
</span><br>
<span class='lastnamedet'>(last name)</span>
<span class='firstnamedet'>(first name)</span>
<span class='midnamedet'>(middle name)</span>
</th>
</tr>
<tr class='first-row'>
<td>NICKNAME<br><span class='user-texts bold'>Nicks</span></td>
<td>BIRTHDATE (mm/dd/yyyy)<br><span class='user-texts bold'>10/25/1994</span></td>
<td>BIRTHPLACE<br><span class='user-texts bold'>Tokyo Japan</span></td>
<td>AGE<br><span class='user-texts bold'>18</span></td>
<td>HEIGHT<br><span class='user-texts bold'>5'7'</span></td>
<td>WEIGHT<br><span class='user-texts bold'>60kg</span></td>
</tr>
<tr class='second-row'>
<td colspan='6'>CITY ADDRESS: <span class='bold'>Plaridel Bulacan</span> </td>
</tr>
<tr class='third-row'>
<td colspan='6'>PROVINCIAL ADDRESS: <span class='bold'>Plaridel Bulacan</span> </td>
</tr>
<tr class='fourth-row'>
<td rowspan='2' ><span class='residentstatus'>RESIDENTIAL STATUS:</span>
<form>
<input type='checkbox' name='gender' value='own' checked='checked'> Own House<br>
<input type='checkbox' name='gender' value='rent'> Rent<br>
<input type='checkbox' name='gender' value='other' > Others (specify): <span class='bold'>Own Mansion</span>
</form>
</td>
<td rowspan='2'><span class='gender'>GENDER:</span>
<form>
<input type='checkbox' name='gender' value='male' checked='checked'> Male<br>
<input type='checkbox' name='gender' value='female' > Female<br>
</form>
</td>
<td colspan='2'>
MOBILE TEL. #: <span class='bold outs'>0926-107-4423</span><br><br>
RESIDENCE TEL. #: <span class='bold outs'>02-25429</span>
</td>
<td colspan='2' >EMAIL ADDRESS:<br><span class='bold outs'>yinkciworks#gmail.com</span></td>
</tr>
<tr class='fifth-row'>
<td colspan='4'>CIVIL STATUS:<br>
<input type='checkbox' name='civil-stat' value='single' checked='checked'> Single
<input type='checkbox' name='civil-stat' value='married' > Married
<input type='checkbox' name='civil-stat' value='single-parent' > Single Parent
<input type='checkbox' name='civil-stat' value='widow' > Widow
<input type='checkbox' name='civil-stat' value='other-status'> Others:
<span class='bold'>Complicated</span>
</td>
</tr>
<tr class='sixth-row'>
<td colspan='2' rowspan='2'>Nationality<br><br>
<input type='checkbox' name='filipino' value='filipino' checked='checked'> Filipino<br>
<input type='checkbox' name='othersnationalit' value='female' > Others (specify):
<span class='bold outs'>Alien Gender</span>
</td>
<td colspan='4'>SSS:
<span class='bold'>29-7098-7685-456</span>
       
TIN:
<span class='bold'>29-7098-7685-456</span>
</td>
</tr>
<tr class='seventh-row'>
<td colspan='4'>CURRENT ACTIVITIES:
<span class='bold'>Nandemonai</span>
</td>
</tr>
</table>
<!--==========================================
EMPLOYMENT HISTORY
============================================= -->
<p class='blackened'>EMPLOYMENT HISTORY</p>
<table class='table-two'>
<tr>
<th>COMPANY NAME</th>
<th>LAST POSITION</th>
<th>IMMEDIATE SUPERIOR</th>
<th>CONTACT NUMBER</th>
<th>INCLUSIVE DATES</th>
<th>REASON FOR LEAVING</th>
<th>SALARY</th>
</tr>
<tr class='table2-first-row'>
<td><span class='bold'>iConcept Global</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Supervisor</span></td>
<td><span class='bold'>0926-107-4423</span></td>
<td><span class='bold'>Oct 25 1994</span></td>
<td><span class='bold'>Mayaman na</span></td>
<td><span class='bold'>100,000</span></td>
</tr>
<tr class='table2-first-row'>
<td><span class='bold'>iConcept Global</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Supervisor</span></td>
<td><span class='bold'>0926-107-4423</span></td>
<td><span class='bold'>Oct 25 1994</span></td>
<td><span class='bold'>Mayaman na</span></td>
<td><span class='bold'>100,000</span></td>
</tr>
<tr class='table2-first-row'>
<td><span class='bold'>iConcept Global</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Supervisor</span></td>
<td><span class='bold'>0926-107-4423</span></td>
<td><span class='bold'>Oct 25 1994</span></td>
<td><span class='bold'>Mayaman na</span></td>
<td><span class='bold'>100,000</span></td>
</tr>
<tr class='table2-first-row'>
<td><span class='bold'>iConcept Global</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Supervisor</span></td>
<td><span class='bold'>0926-107-4423</span></td>
<td><span class='bold'>Oct 25 1994</span></td>
<td><span class='bold'>Mayaman na</span></td>
<td><span class='bold'>100,000</span></td>
</tr>
</table>
<!--==========================================
FAMILY BACKGROUND
============================================= -->
<p class='blackened'>FAMILY BACKGROUND</p>
<table class='table-three'>
<tr>
<th></th>
<th>NAME</th>
<th>AGE</th>
<th>OCCUPATION</th>
<th>COMPANY/SCHOOL</th>
</tr>
<tr>
<td>Father</td>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td>Mother</td>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td rowspan='4'>Brothers & Siters</td>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td>Spouse</td>
<td><span class='bold'>Not available</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td>Children</td>
<td><span class='bold'>Not available</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
</table>
<!--==========================================
REFERENCES
============================================= -->
<p class='blackened'>REFERENCES</p>
<table class='table-four'>
<tr>
<th>NAME</th>
<th>POSITION</th>
<th>COMPANY</th>
<th>ADDRESS</th>
<th>CONTACT NO.</th>
</tr>
<tr>
<td><span class='bold centerme'>Shana Hirai</span></td>
<td><span class='bold centerme'>Flame Haze</span></td>
<td><span class='bold centerme'>Shakugan no Shana</span></td>
<td><span class='bold centerme'>Anime</span></td>
<td><span class='bold centerme'>0926-107-4423</span></td>
</tr>
<tr>
<td rowspan='9' colspan='3' class='etu'>How did you know of the opening?<br>
<input type='checkbox' name='opening' value='news' checked> Newspaper Ad <br>
<input type='checkbox' name='opening' value='school'> School Placement <br>
<input type='checkbox' name='opening' value='walkin'> Walk-in<br>
<input type='checkbox' name='opening' value='referal' checked> Referral of: <span class='bold outs'>Friend</span> <br>
<input type='checkbox' name='opening' value='other-ads' checked> Others (specify): <span class='bold outs'>Facebook Ads</span><br><br>
</td>
<td rowspan='9' colspan='2'>
<span class='emergency italic'>In case of emergency please contact:</span><br>
Name: <span class='bold'> Sakai Yuji</span><br>
Contact No.: <span class='bold'>0926-107-4423</span><br>
Relation to you: <span class='bold'>Tomodachi</span><br><br>
</td>
</tr>
</table>
<p class='ihereby'>I hereby certify that the above information is true and correct and I hereby authorize Cabalen to verify the said information.</p>
<table class='last-part'>
<tr>
<th><span class=''>   signed already</span><br><br>
<span class='sign-details'> Applicant's Signature</span></th>
<th><span class=''>                          Oct 23 2017</span><br><br>
<span class='date-details'>                          Date</span></th>
</tr>
</table>
</div>
</body>
</html>
";
$mpdf=new mPDF('utf-8', 'Letter', 0, '', 2, 2, 12, 2, 2, 2);
$mpdf->WriteHTML($html);
$mpdf->SetDisplayMode('fullpage');
$mpdf->shrink_tables_to_fit = 1;
$mpdf->Output();
?>

The mPDF docs state that the first argument of Output() is the file path, second is the saving mode - you need to set it to 'F'.
$mpdf->Output('filename.pdf','F'); //Only save to File
Updated: You may need this too:
$mpdf->Output('filename.pdf','D');

I already found the cause, its the maxcdn bootstrap link, I only removed the link then everything went fine.

Related

Python regex ignore new line

I have web page look like this
<td valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="main_tb3">
<tr>
<td colspan="2">
<div align="center">
<a href="/title/name.php" target="_blank">
<img src="./movie/image.jpg" alt="TitleName" border="0" height="100" width="225" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><h1 align="center">Title - secondname</h1></td>
</tr>
<tr>
<td><span class="style10">Cat1 :</span></td>
<td>1st name</td>
</tr>
<tr>
<td width="32%"><span class="style10">Cat2 :</span></td>
<td width="68%"><b><i>secondname</i></b></td>
</tr>
<tr>
<td><span class="style10">cat4 :</span></td>
<td>Bla bla</td>
</tr>
<tr>
<td><span class="style10">Cat3 :</span></td>
<td>thirdName2</td>
</tr>
</table>
</td>
<td valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="main_tb3">
<tr>
<td colspan="2">
<div align="center">
<a href="/title/name.php" target="_blank">
<img src="./movie/image.jpg" alt="TitleName" border="0" height="100" width="225" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><h1 align="center">Title - secondname</h1></td>
</tr>
<tr>
<td><span class="style10">Cat1 :</span></td>
<td>1st name</td>
</tr>
<tr>
<td width="32%"><span class="style10">Cat2 :</span></td>
<td width="68%"><b><i>secondname</i></b></td>
</tr>
<tr>
<td><span class="style10">cat4 :</span></td>
<td>Bla bla</td>
</tr>
<tr>
<td><span class="style10">Cat3 :</span></td>
<td>thirdName2</td>
</tr>
</table>
</td>
I would like to get certain values from this site using python regex.
After <div align="center"> I like to get href value: "/title/name.php" and img src: "./movie/image.jpg" and Title - secondname from <h1 align="center">Title - secondname</h1>
i have tried this:
regex = 'class="main_tb3"*\n<a href="(.+?)" target="_blank">\n<img src="(.+?)"'
please help me
you can use below regex
For href value: <a href="(.*?)"
For Image src: <img src="(.*?)"
For Title: titleid=12">(.*?)<
You will find it a lot simpler to install something like BeautifulSoup to do this:
from bs4 import BeautifulSoup
html = """
<td valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="main_tb3">
<tr>
<td colspan="2">
<div align="center">
<a href="/title/name.php" target="_blank">
<img src="./movie/image.jpg" alt="TitleName" border="0" height="100" width="225" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><h1 align="center">Title - secondname</h1></td>
</tr>
<tr>
<td><span class="style10">Cat1 :</span></td>
<td>1st name</td>
</tr>
<tr>
<td width="32%"><span class="style10">Cat2 :</span></td>
<td width="68%"><b><i>secondname</i></b></td>
</tr>
<tr>
<td><span class="style10">cat4 :</span></td>
<td>Bla bla</td>
</tr>
<tr>
<td><span class="style10">Cat3 :</span></td>
<td>thirdName2</td>
</tr>
</table>
</td>
<td valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="main_tb3">
<tr>
<td colspan="2">
<div align="center">
<a href="/title/name.php" target="_blank">
<img src="./movie/image.jpg" alt="TitleName" border="0" height="100" width="225" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><h1 align="center">Title - secondname</h1></td>
</tr>
<tr>
<td><span class="style10">Cat1 :</span></td>
<td>1st name</td>
</tr>
<tr>
<td width="32%"><span class="style10">Cat2 :</span></td>
<td width="68%"><b><i>secondname</i></b></td>
</tr>
<tr>
<td><span class="style10">cat4 :</span></td>
<td>Bla bla</td>
</tr>
<tr>
<td><span class="style10">Cat3 :</span></td>
<td>thirdName2</td>
</tr>
</table>
</td>"""
soup = BeautifulSoup(html)
for table in soup.find_all("table", class_="main_tb3"):
print table.find('a').get('href')
print table.find('h1').text
For the HTML you have given, this will print the following:
/title/name.php
Title - secondname
/title/name.php
Title - secondname

Creating PDF with TCPDF shows Undefined index: cols in tcpdf/tcpdf.php on line 16928

I wanted to use TCPDF to generate a PDF report. but every time it shows me error on line 16928 and I can't understand what to do...
It would be great if you could help me
here is my code:
<?php
$html = "
<html>
<head>
<link rel='stylesheet' href='form.css'>
</head>
<body>
<div class='header'>
<h4>وزارت بهداشت، درمان و آموزش کشور</h4>
<h4>Ministry of Health & Medical Education</h4>
<table>
<tr>
<td class='engterm'>University of medical science:</td><td class='val'>[SAMPLE_ECHO]</td><td class='perterm'>دانشگاه علوم پزشکی:</td>
</tr>
<tr>
<td class='engterm'>Medical center:</td><td class='val'>[SAMPLE_ECHO]</td><td class='perterm'>مرکز پزشکی آموزشی درمانی:</td>
</tr>
</table>
</div>
<div class='body'>
<table class='main' border='1'>
<tr>
<td class='main' colspan='1' rowspan='2' style='text-align: left;'>
<table style='margin: 0 auto;'>
<tr>
<td class='engterm'>Clinic no.:</td><td class='val'>[sample]</td><td class='perterm'>شماره درمانگاهی:</td>
</tr>
</table>
</td>
<td class='main' colspan='2' rowspan='2' style='text-align: center; width: 50%'>
<h4>برگ خلاصه پرونده</h4>
<h4>Unit Summery Sheet</h4>
</td>
<td class='main' colspan='1' rowspan='2' style='direction: ltr;'>
<table style='margin: 0 auto;'>
<tr>
<td class='engterm'>Unit no.:</td><td class='val'>[sample]</td><td class='perterm'>شماره پرونده:</td>
</tr>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td class='main' rowspan='1'>
<table class='data'>
<td>Attending Physician:</td><td>SampleData</td><td>پزشک معالج:</td>
</table>
</td>
<td class='main' rowspan='2'>
<table class='data'>
<tr><td>Ward:</td><td>Sample</td><td>بخش:</td></tr>
<tr><td>Room:</td><td>Sample</td><td>اتاق:</td></tr>
<tr><td>Bed:</td><td>Sample</td><td>تخت:</td></tr>
</table>
</td>
<td class='main' rowspan='1'>
<table class='data'>
<td>Name:</td><td>Sample</td><td>نام:</td>
</table>
</td>
<td class='main' rowspan='1'>
<table class='data'>
<td>Family name:</td><td>Sample</td><td>نام خانوادگی:</td>
</table>
</td>
</tr>
<tr>
<td class='main'>
<table class='data'>
<td>Admission date:</td><td>Sample</td><td>تاریخ پذیرش:</td>
</table>
</td>
<td class='main'>
<table class='data'>
<td>Date of Birth:</td><td>Sample</td><td>تاریخ تولد:</td>
</table>
</td>
<td class='main'>
<table class='data'>
<td>Father's name:</td><td>Sample</td><td>نام پدر:</td>
</table>
</td>
</tr>
<tr>
<td class='main'>
<table class='data'>
<td></td><td>Sample</td><td>تاریخ ترخیص:</td>
</table>
</td>
<td class='main'>
<table class='data'>
<td>Occupation:</td><td>Sample</td><td>شغل:</td>
</table>
</td>
<td class='main'>
<table class='data'>
<td>Marriage status:</td>
<td>
<input type='radio' name='marriage_status' value='married'>متاهل / Married<br>
<input type='radio' name='marriage_status' value='single'>مجرد / Single
</td>
<td>وضعیت تاهل:</td>
</table>
</td>
<td class='main'>
<table class='data'>
<td>Sex:</td>
<td>
<input type='radio' name='sex' value='male'>مرد / Male<br>
<input type='radio' name='sex' value='female'> زن / Female
</td>
<td>جنسیت:</td>
</table>
</td>
</tr>
<tr>
<td colspan='4'>
<table class='data'>
<td colspan='1' style='text-align: left;'>Address:</td><td colspan='2'>Sample</td><td colspan='1' style='text-align: right;'>آدرس:</td>
</table>
</td>
</tr>
<tr>
<td colspan='4'>
<table class='data'>
<td colspan='1'>Final Diagnosis:</td>
<td colspan='2'>Sample</td>
<td colspan='1'>تشخصی نهایی:</td>
</table>
</td>
</tr>
<tr>
<td colspan='4'>
<table class='data'>
<td colspan='1'>Medical & Surgical Procedures:</td>
<td colspan='2'>Sample</td>
<td colspan='1'>اقدامات درمانی و اعمال جراحی:</td>
</table>
</td>
</tr>
<tr>
<td colspan='4'>
<table class='data'>
<td colspan='1'>Results of Paraclinical Examination:</td>
<td colspan='2'>Sample</td>
<td colspan='1'>پاراكلينيكي آزمايشات نتايج:</td>
</table>
</td>
</tr>
<tr>
<td colspan='4'>
<table class='data'>
<td colspan='1'>Disease Progress (Cause of Death):</td>
<td colspan='2'>Sample</td>
<td colspan='1'>سیر بیماری (درصورت فوت، علت مرگ):</td>
</table>
</td>
</tr>
<tr>
<td colspan='4'>
<table class='data'>
<td colspan='1'>Patient's Condition on Discharge:</td>
<td colspan='2'>Sample</td>
<td colspan='1'>وضعیت بیمار هنگام ترخیض:</td>
</table>
</td>
</tr>
<tr>
<td colspan='4'>
<table class='data'>
<td colspan='1'>Recommendations after discharge:</td>
<td colspan='2'>Sample</td>
<td colspan='1'>توصیه‌های پس از ترخیض:</td>
</table>
</td>
</tr>
<tr>
<td colspan='4'>
<table class='data'>
<td colspan='1'>Attending Physician's Name & Signature:</td>
<td colspan='2'>Sample</td>
<td colspan='1'>نام و امضا پزشک معالج:</td>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>";
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
if (#file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->SetFont('helvetica', '', 9);
$pdf->AddPage();
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output('htmlout.pdf', 'I');
?>
When reading the page from web server, it shows me the following error:
Notice: Undefined index: cols in /home/aien/public_html/Arash.Sammak/JSON Return/tcpdf/tcpdf.php on line 16928
You have to add a valid <thead> element to every table. TCPDF parses the <thead> element to determine the number of columns in a table when it outputs tables in PDF.
Also, check your HTML twice is valid or not if some other errors keep occurring.
Hope this helps.

how to use sql query result in html table

I am trying to create a html table showing results from php sql query. it is a result page of students php code is as under
$r1=$_GET["r"];
$con=mysqli_connect(localhost,chumspai_tlss,Tls121,chumspai_tlsResult);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM nursery_blue_ WHERE sr_='$r1'");
while($row = mysqli_fetch_array($result))
{
html code is
<pre>
<form name="frmResult" id="frmResult" action="" method="post" onsubmit="return checkEmpty();">
<table width="80%" cellpadding="5" cellspacing="5" border="0">
<tr>
<td class="heading noborder">Enter Your Roll Number:</td>
<td class="noborder"><input type="text" id="r" name="r" value="" /></td>
</tr>
<tr>
<!--
<td class="heading noborder">Enter Your Name:</td>
<td class="noborder"><input type="text" id="name" name="name" value="" /></td>
</tr>
<tr>
<td class="heading noborder">Search by</td>
<td class="noborder"><input type="radio" id="option" name="option" value="rno" checked="checked" />
Roll No
<input type="radio" id="option" name="option" value="name" />
Name </td>
</tr>
-->
<tr>
<td class="noborder"> </td>
<td class="noborder"><input type="submit" name="submit" value="Search" />
<input type="reset" name="reset" value="Clear" />
</td>
</tr>
<!--<tr>
<td colspan="2"> <embed src="images/wait.swf"></embed></td>
</tr> -->
</table>
</form>
<div style="border:1px solid #000000;">
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr>
<td class="heading grey" width="30%">RNO</td>
<td><?php
Print $row['sr_'];
?>
</td>
</tr>
<tr>
<td class="heading grey">NAME</td>
<td class="shade"></td>
</tr>
<tr>
<td class="heading grey">FATHER</td>
<td></td>
</tr>
<tr>
<td class="heading grey">regno</td>
<td></td>
</tr>
</table>
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr class="grey">
<td rowspan="2" class="heading">Sr.no </td>
<td rowspan="2" class="heading">Name of subject </td>
<td rowspan="2" class="heading">Maximum Marks</td>
<td colspan="7" class="heading">detail of marks Obtained</td>
<tr class="grey">
<td class="heading">PART ONE</td>
<td class="heading">Total</td>
</tr>
<tr>
<td>1</td>
<td>Urdu</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>2</td>
<td>English</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>Islamyat</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>4</td>
<td>pakstudies</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>6</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr>
<td>7</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="shade">
<td>8</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="shade">
<td>9</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="grey">
<td colspan="2" class="heading">TOTAL</td>
<td class="heading">1100</td>
<td colspan="4" class="heading"></td>
</tr>
<tr class="grey">
<td colspan="3" class="heading">NOTIFICATION</td>
<td class="heading"></td>
<td class="heading"></td>
<td colspan="2" class="heading"></td>
</tr>
<tr>
<td colspan="7">(i) This provisional result intimation is issued as a notice only. Errors and omissions are excepted.</td>
</tr>
</table>
</pre>
please help me how to embed this php query with this html table and html form also.
you are not so far.
The variable $row is an array containing your data. Try this to see it's structure in your while call:
print_r($row);
Using this command you will see the name of each item of your array. Note it somewhere. Then you can do something like this:
...<td><?php echo $row['desired_column_name']; ?></td>...
If you receive data from your mysql query, this should do the trick.
Hope it helps,
Paul
Try This :
$result = mysql_query("select * from emp");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td id=SrNo$cnt >".$row['eno']."</td>";
echo "<td id=ItemId$cnt >".$row['eId']."</td>";
echo "<td>". "<button name='Update' id='update' onclick='show(".$cnt.")'>UPDATE</button>"."</td>";
echo "<td>". "<button name='Report' id='show' onclick='Report(".$row['SrNo'].")'>REPORT</button>"."</td>";
echo "</tr>";
echo "<div id=show$cnt>";
echo "</div>";
$cnt++;
}

check email address used by others in database, if yes, pop up alert, if no, continue to next step

i am constructing a registration page for new members. after filling in the form, it will proceed to the confirm page. after confirmation, it will proceed to the reg_add.php to add the data from the form to the database.
reg_new.php --> reg_confirm.php --> reg_add.php
i am trying to edit the code in the confirm page (reg_confirm.php) to include the email availability check. it seems that it can automatically detect the duplicate email and after clicking the confirm button.
Duplicate entry 'shop#gmail.com' for key 'PRIMARY' will be shown.
yet, it is not success to have a pop up alert and stay in the confirm page. please help.
<?php
session_start();
$_SESSION['email'] = $_POST['email_reg'];
$_SESSION['password'] = $_POST['password_reg'];
$_SESSION['name_reg'] = $_POST['name_reg'];
$_SESSION['month'] = $_POST['month'];
$_SESSION['telephone_reg'] = $_POST['telephone_reg'];
$_SESSION['room_reg'] = $_POST['room_reg'];
$_SESSION['floor_reg'] = $_POST['floor_reg'];
$_SESSION['block_reg'] = $_POST['block_reg'];
$_SESSION['building_reg'] = $_POST['building_reg'];
$_SESSION['estate_reg'] = $_POST['estate_reg'];
$_SESSION['street_reg'] = $_POST['street_reg'];
$_SESSION['district_reg'] = $_POST['district_reg'];
$_SESSION['region_reg'] = $_POST['region_reg'];
$regemail = $_POST["email_reg"];
$connect = mysql_connect("127.0.0.1","root","") or die("not connecting");
mysql_select_db("shop") or die("no db :'(");
$numrows = mysql_query("SELECT membermail FROM member WHERE memberemail='$regemail'");
if ($numrows!=0)
{
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";
}
?>
</head>
<body>
<div align="center" class="style1"><span class="style2">Registeration Confirm</span>
<p class="style2"> </p>
<form action="reg_add.php" method="post" enctype="multipart/form-data" name="form1">
<table width="602" height="180" border="1">
<tr>
<td colspan="3">Login Information</td>
</tr>
<tr>
<td width="160" class="style6">Email address: </td>
<td colspan="2"><span class="style7"><?php echo $_SESSION['email']?></span></td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="3">User information </td>
</tr>
<tr>
<td><span class="style6">Name:</span></td>
<td colspan="2"><?php echo ($_SESSION['name_reg'])?></td>
</tr>
<tr>
<td><span class="style6">Month of birth :</span></td>
<td colspan="2"><?php echo ($_SESSION['month'])?>
</tr>
<tr>
<td><span class="style6">Contact telephone:</span></td>
<td colspan="2"><?php echo ($_SESSION['telephone_reg'])?></td>
</tr>
<tr>
<td rowspan="8"><span class="style6">Contact address:</span></td>
<td width="153"><p class="style6">Room/ Flat no.: </p> </td>
<td width="267"><p class="style6"><?php echo ($_SESSION['room_reg'])?></p> </td>
</tr>
<tr>
<td><span class="style6">Floor: </span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['floor_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Block/ Tower:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['block_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Building:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['building_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Estate: </span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['estate_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Street:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['street_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">District:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['district_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Region: </span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['region_reg'])?></span></td>
</tr>
<tr>
<td colspan="3" class="style6"> </td>
</tr>
</table>
<p>
<input name="confirm" type="submit" id="confirm" value="Confirm">
</p>
</form>
<p>
<input name="modifty" type="submit" id="modifty" value="Modify" onClick="history.go(-1)">
</p>
</div>
</body>
</html>
Your problem is how you are retrieving the number of rows from the database.
mysql_query() does not retrieve the number of rows. It retrieves a result set.
Instead of:
$numrows = mysql_query("SELECT membermail FROM member WHERE memberemail='$regemail'");
if ($numrows!=0)
{
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";
}
Use:
$email = mysql_real_escape_string($_POST["email_reg"]);
$result = mysql_query("SELECT COUNT(memberemail) AS emailCount FROM member WHERE memberemail='{$email}'");
$row = mysql_fetch_row($result);
if($row[0]>0){
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";
}
ALWAYS make sure you escape your data before using it in a database query.

Pulling all the form values from a posted array

I have this form:
<form method="post" action="mypage.php" orderform="" name="" id="orderform">
<a id="add">+</a>
<table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable">
<tbody>
<tr>
<td width="33%">Product Code (e.g 66203)</td>
<td width="33%">mtrs sq Required (e.g 10)</td>
<td width="33%">Preview Image</td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode[]" name="prodcode[]" class=" "></td>
<td class="meterage"><input type="text" id="meterage[]" name="meterage[]"></td>
<td class="imgsample"></td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode[]" name="prodcode[]" class=" "></td>
<td class="meterage"><input type="text" id="meterage[]" name="meterage[]"></td>
<td class="imgsample"></td>
</tr>
</tbody>
</table>
<button>Submit</button>
</form>
I am trying to receive the post and print the associate product value with its meterage...as below ( this only seems to return the last result) any ideas?
$number_of_products=count($_POST['prodcode']);
for ( $i=0; $i<$number_of_products; $i++){
$orderdetails = $_POST['prodcode'][$i]." has the meterage: ".$_POST['meterage'][$i]."<br/>";
}
You're overwriting the content of $orderdetails each time the for loop is run.
Try something like this:
$number_of_products=count($_POST['prodcode']);
$orderdetails = "<h1>Order Details</h1>";
for ( $i=0; $i<$number_of_products; $i++){
$orderdetails .= $_POST['prodcode'][$i]." has the meterage: ".$_POST['meterage'][$i]."<br/>";
}
Try indexing the prodcode[] and meterage[] names on your input fields, i.e.:
<form method="post" action="mypage.php" orderform="" name="" id="orderform">
<a id="add">+</a>
<table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable">
<tbody>
<tr>
<td width="33%">Product Code (e.g 66203)</td>
<td width="33%">mtrs sq Required (e.g 10)</td>
<td width="33%">Preview Image</td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode_0" name="prodcode[0]" class=" "></td>
<td class="meterage"><input type="text" id="meterage_0" name="meterage[0]"></td>
<td class="imgsample"></td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode_1" name="prodcode[1]" class=" "></td>
<td class="meterage"><input type="text" id="meterage_1" name="meterage[1]"></td>
<td class="imgsample"></td>
</tr>
</tbody>
</table>
<button>Submit</button>
</form>
it because you overwrite it everytime
change
$orderdetails =
to
$orderdetails .=

Categories