Unable to upload .avi files using php form - php

have tried uploading .avi video formats but the page just refreshes and the file is not uploaded all other types type images and everything is getting uploaded im posting my code here look for file uploding sections with cwf and ve
<?php
$n=5;
$exp_no="";
$shot_no="";
$file_name1="";
$file_name2="";
$remarks="";
$cwf="";
$vedio="";
$conn=mysqli_connect("localhost","root","","project");
if(!$conn){
die("connection failed");
echo "<br/>";
}
$query="select stage from experimentdetails where NO='{$exp_no}'";
$res=mysqli_query($conn,$query);
if(mysqli_num_rows($res)>0){
$r=mysqli_fetch_row($res);
$n=$r[0];
}
session_start();
$exp_no=$_SESSION["expno_add"];
$s=mysqli_query($conn,"select ShotNo from shotdetails where ExpNo='{$exp_no}'");
$res=mysqli_fetch_row($s);
$shot_no=$res[0];
if(isset($_POST["submit"]))
{
$remarks=$_POST["remarks"];
$cap=array(8);
$off=array(8);
$cv=array(8);
$cptp=array(8);
$pul=array(8);
$del=array(8);
$vel=array(8);
for($i=0;$i<8;$i++)
{
if($i<$n)
{
$j=$i+1;
$cap[$i]=$_POST["cv{$j}"];
$off[$i]=$_POST["off{$j}"];
$cv[$i]=$_POST["cc{$j}"];
$cptp[$i]=$_POST["cpt{$j}"];
$pul[$i]=$_POST["pw{$j}"];
$del[$i]=$_POST["del{$j}"];
$vel[$i]= $_POST["vel{$j}"];
}
else{
$cap[$i]=0;
$off[$i]=0;
$cv[$i]=0;
$cptp[$i]=0;
$pul[$i]=0;
$del[$i]=0;
$vel[$i]=0;
}
}
if($_FILES['cwf']['name']!="")
{
$fname=$_FILES["cwf"];
$uploaddir = 'cwf/';
if (is_uploaded_file($fname['tmp_name']))
{
$filname = basename($fname['name']);
$uploadfile = $uploaddir . basename($fname['name']);
if (move_uploaded_file ($fname['tmp_name'], $uploadfile))
$r = "File " . $filname . " was successfully uploaded and stored.<br>";
else
$r = "Could not move ".$fname['tmp_name']." to ".$uploadfile."<br>";
}
else
$r = "File ".$fname['name']." failed to upload.";
$file_name1='cwf/'.$file_name1;
}
if($_FILES['ve']['name']!="")
{
$fname=$_FILES["ve"];
$uploaddir = 'upload/';
if (is_uploaded_file($fname['tmp_name']))
{
$filname = basename($fname['name']);
$uploadfile = $uploaddir . basename($fname['name']);
if (move_uploaded_file ($fname['tmp_name'], $uploadfile))
$r = "File " . $filname . " was successfully uploaded and stored.<br>";
else
$r = "Could not move ".$fname['tmp_name']." to ".$uploadfile."<br>";
}
else
$r = "File ".$fname['name']." failed to upload.";
$file_name2='upload/'.$file_name2;
}
$query="insert into shotdetails values($shot_no,$cap[0],$cap[1],$cap[2],$cap[3],$cap[4],$cap[5],$cap[6],$cap[7],$off[0],$off[1],$off[2],$off[3],$off[4],$off[5],$off[6],$off[7],$cptp[0],$cptp[1],$cptp[2],$cptp[3],$cptp[4],$cptp[5],$cptp[6],$cptp[7],$pul[0],$pul[1],$pul[2],$pul[3],$pul[4],$pul[5],$pul[6],$pul[7],$del[0],$del[1],$del[2],$del[3],$del[4],$del[5],$del[6],$del[7],$vel[0],$vel[1],$vel[2],$vel[3],$vel[4],$vel[5],$vel[6],$vel[7],$file_name1,$file_name2,$remarks,$exp_no,$cv[0],$cv[1],$cv[2],$cv[3],$cv[4],$cv[5],$cv[6],$cv[7])";
mysqli_query($conn,$query);
}
mysqli_close($conn);
?>
<html>
<head>
<title>ADD Shot</title>
<style>
select {
padding:3px;
margin: 0;
-webkit-border-radius:4px;
-moz-border-radius:4px;
border-radius:4px;
-webkit-box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset;
-moz-box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset;
box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset;
background: #f8f8f8;
color:#888;
border:none;
outline:none;
display: inline-block;
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
cursor:pointer;
}
/* Targetting Webkit browsers only. FF will show the dropdown arrow with so much padding. */
#media screen and (-webkit-min-device-pixel-ratio:0) {
select {padding-right:18px}
}
label {position:relative}
label:after {
content:'<>';
font:11px "Consolas", monospace;
color:#aaa;
-webkit-transform:rotate(90deg);
-moz-transform:rotate(90deg);
-ms-transform:rotate(90deg);
transform:rotate(90deg);
right:8px; top:2px;
padding:0 0 2px;
border-bottom:1px solid #ddd;
position:absolute;
pointer-events:none;
}
label:before {
content:'';
right:6px; top:0px;
width:20px; height:20px;
background:#f8f8f8;
position:absolute;
pointer-events:none;
display:block;
}
.c ul li {
margin-top: 11px;
margin-right: 6px;
padding: 0px;
display: inline-block;
font-family: open-sans, Araial, Helvetica, sans-serif;
font-size:14px;
}
.c li a {
margin-left: 10px;
color:black;
padding-right: 20px;
text-decoration: none;
}
.c{
margin-left: 20px;
border-right: 1px solid rgba(1,1,1,0.20);
border-left: 1px solid rgba(1,1,1,0.20);
border-radius:5px;
width:98%;
margin-top: 10px;
}
#nav {
height: 40px;
border-radius:3px;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
}
</style>
</head>
<body>
<div class="c">
<ul id="nav">
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Add Experiment
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Modify Experiment
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Delete Experiment
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Create New Shot
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Delete Shot
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Add Component
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Modify Component
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Delete Component
</li>
</ul>
</div>
<center style="margin-top:5%">
<form action="add_shot1.php" method="POST" name="add" enctype="multipart/form-data">
<table cellspacing="4" cellpadding="4" class="cap">
<tr>
<th>Stage No.</th>
<th>Charging Voltage(kV)</th>
<th>Offset(mm)</th>
<th>Coil Current(kA)</th>
<th>Current Pulse Time period(ms)</th>
<th>Pulse Width(ms)</th>
<th>Delay(ms)</th>
<th>Velocity</th>
</tr>
<?php
for ($x = 1; $x <= $n; $x++) {
echo "<tr>";
echo "<td align='center'>" . $x . "</td>";
echo "<td align='center' ><input type='number' class='text' name='cv{$x}' value='' style=' height:30px;'/></td>";
echo "<td align='center'><input type='number' class='text' name='off{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='cc{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='cpt{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='pw{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='del{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='vel{$x}' value=''style=' height:30px;'/></td>";
echo"</tr>";
}
?>
<tr>
<td colspan='4'> Current wave form file: &nbsp <input type='file' name='cwf' value='' class='text'/> </td>
</tr>
<tr >
<td colspan='4' >Video File: <input type='file' name='ve' value='' class='text'/></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Remarks</td>
<td><textarea rows="10" cols="40" name="remarks" value=""></textarea></td>
</tr>
<tr>
<td colspan=4 align='center'><input type="submit" name="submit" value="submit" /></td>
</tr>
</table>
</form>
</center>
</body>
</html>

Related

How to remove extra borders in continues pages of HTML table in mpdf?

<div id="page-details">
<table style="page-break-inside: avoid !important;" width="1280px" cellspacing="0" cellpadding="0">
<tr style="page-break-inside: avoid !important; ">
<td width="1280px">
<table autosize="1" cellspacing="0" cellpadding="0" width="1280px">
<tr>
<td style="border-right:1px solid; height:25px; text-align:center;" width="40px">No</td>
<td width="320px" style="border-right:1px solid; text-align:center; height:25px;">Typology</td>
<td width="415px" style="border-right:1px solid; text-align:center; height:25px;">Description of Goods</td>
<td width="100px" style="border-right:1px solid; text-align:center; height:25px;">Width</td>
<td width="100px" style="border-right:1px solid; text-align:center; height:25px;">Height</td>
<td width="80px" style="border-right:1px solid; text-align:center; height:25px;">Qty</td>
<td width="100px" style="border-right:1px solid; text-align:center; height:40px;">Sq Feet
</td>
<td width="125px" style="text-align:center; height:40px;">Total
</td>
</tr>
</table>
</td>
</tr>
<!-- for loop start -->
<?php
if($quotation->items != null && count($quotation->items) > 0) {
$index = 1;
for ($i=0; $i < count($quotation->items); $i++) {
?>
<tr style="page-break-inside: avoid !important;">
<td width="1280px">
<table cellspacing="0" cellpadding="0" width="1280px" style="overflow-wrap: break-word; page-break-inside: avoid !important; ">
<tr>
<td style="border-top:1px solid; border-right:1px solid; border-bottom: 1px solid; height:75px; text-align:center;" width="40px">
<?php echo $index++; ?>
</td>
<td width="320px" style="border-top:1px solid; border-right:1px solid; border-bottom: 1px solid; height:275px;">
<?php
if ($quotation->items[$i]->seriesType == 7 ||
$quotation->items[$i]->seriesType == 8) {
?>
<img src="<?php echo $quotation->items[$i]->url;?>" style="max-height: 320px; max-width: 275px; padding: 5px;">
<?php
} else {
?>
<img src="<?php echo $quotation->items[$i]->url;?>" style="max-height: 320px; max-width: 275px; padding: 5px;">
<?php
}
?>
</td>
<td width="415px" style="word-wrap: break-word; border-top:1px solid; border-right:1px solid; border-bottom: 1px solid; overflow-wrap: break-word; padding: 5px;">
<?php
echo "Pattern: <b>" . $quotation->items[$i]->patternName . "</b>";
?>
<br>
<p style="font-size: 20px;">
<?php
echo "Series: <b>" . $quotation->items[$i]->seriesName . "</b>";
?>
<br>
<?php
echo "Section Company: <b>" . $quotation->items[$i]->companyName . "</b>";
?>
<br>
<?php
echo "Glass: <b>" . $quotation->items[$i]->type . "</b>";
?>
<br>
<?php
echo "Color: <b>" . $quotation->items[$i]->colorType . "</b>";
?>
</p>
<br>
<?php
if (isset($quotation->items[$i]->location)) {
?>
<p style="font-size: 20px; font-weight: bold;">
<?php
echo "Location: " . $quotation->items[$i]->location;
?>
</p>
<?php
}
?>
<br>
<p style="font-size: 20px;">
<?php
if ($quotation->items[$i]->lockId > 0) {
echo "Lock - <b>" . $quotation->items[$i]->lockName . "</b>";
?>
</p>
<?php
}
?>
<?php
if (!empty($quotation->items[$i]->lockDescription)) {
?>
<p style="font-size: 20px; margin-left: 20px;">
<?php
echo "Description - <b>" . $quotation->items[$i]->lockDescription . "</b>";
?>
</p>
<?php
}
?>
<?php
if (!empty($quotation->items[$i]->make)) {
?>
<p style="font-size: 20px; margin-left: 20px;">
<?php
echo "Make - <b>" . $quotation->items[$i]->make . "</b>";
?>
</p>
<?php
}
?>
<?php
if (!empty($quotation->items[$i]->model)) {
?>
<p style="font-size: 20px; margin-left: 20px;">
<?php
echo "Model - <b>" . $quotation->items[$i]->model . "</b>";
?>
</p>
<?php
}
?>
<?php
if (!empty($quotation->items[$i]->brand)) {
?>
<p style="font-size: 20px; margin-left: 20px;">
<?php
echo "Brand - <b>" . $quotation->items[$i]->brand . "</b>";
?>
</p>
<br>
<?php
}
?>
</td>
<td width="100px" style="border-top:1px solid; border-right:1px solid; border-bottom: 1px solid; text-align:center; height:75px;">
<?php echo number_format($quotation->items[$i]->totalWidth, 2); ?>
</td>
<td width="100px" style="border-top:1px solid; border-right:1px solid; border-bottom: 1px solid; text-align:center; height:75px;">
<?php echo number_format($quotation->items[$i]->totalHeight, 2); ?>
</td>
<td width="80px" style="border-top:1px solid; border-right:1px solid; border-bottom: 1px solid; text-align:center; height:75px;">
<?php echo $quotation->items[$i]->qty; ?>
</td>
<td width="100px" style="border-top:1px solid; border-right:1px solid; border-bottom: 1px solid; text-align:center; height:75px;">
<?php
$totalSqFeet = $quotation->items[$i]->totalFoot * $quotation->items[$i]->qty;
echo number_format($totalSqFeet, 2);
?>
</td>
<td width="125px" style="border-top:1px solid; border-bottom: 1px solid;text-align:center; height:75px;">
<?php echo number_format($quotation->items[$i]->total, 2); ?>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
}
?>
<!-- for loop end -->
</table>
</div>
Following is the Image of the issue I am facing in PDF for the reference.
I have placed page-break-inside: avoid !important; code inside table and tr both.
Also set $mpdf->shrink_tables_to_fit = 1; in MPDF object but still I am getting extra borders.

dompdf stops unexpectedly after data collection with mysq

I have a file that converts my MySQL data to PDF using dompdf it works fine but sometimes it just throws 500 error and nothing shows up and after a few moments works and sometimes I am supposed to put a clean back up for it to work. All the is collected successfully with mysql and php but at last some errors in converting the PDF dont know is it dompdf bug or problem with my code. Please check the code below and help me make a better world... I greatly appreciate your help :)
<?php
$idswitch = $_GET['id']; // id for viewing
// Below is optional, remove if you have already connected to your database.
$mysqli = mysqli_connect('...', '..', '..', '...');
$sql=mysqli_query($mysqli,"SELECT * FROM si_invoices WHERE id='$idswitch'")or die(mysql_error());
$row=mysqli_fetch_assoc($sql);
$sample .= "<div style='font-family: Arial, Helvetica, sans-serif; background:#000000; width: 100%; color: #ffffff; padding: 4px; text-align: center; font-size: 120%;' >PROFOMA INVOICE: ID:100".$row['id']."</div>";
$sample .= "<div style='width:100%; height: 120px; background: #ffffff;'>";
$sample .= "<img src='logo-si.png' style='width: 250px; padding: 15px'>";
$sample .= "<div style='font-family: Arial, Helvetica, sans-serif; background:#000000; width: 100%; color: #ffffff; padding: 4px; text-align: center; font-size: 75%' >Interior Exterior General Signs LED Architectural & Modular Sign Systems Traffic & Safety Signs MV No. Plates</div><br>";
$sample .= "<div style='font-family: Arial, Helvetica, sans-serif; position:absolute; top: 35px; left: 300px; width: 400px; border-left: 2px solid #000000; padding-left: 10px; background: #ffffff; font-size: 85%'>
UBUNGO BUSINESS PARK-P.O.BOX 1965 - <br>DAR ES SALAAM-TANZANIA- +255 22 2866500 / 2860440 -<br>068444 422
E-MAIL: headsales#signindustries.co.tz - info#signindustries.co.tz - www.signindustries.co.tz
</div>";
$sample .= "</div>";
$sample .= "<div style='width:100%; margin-top: 15px;'>
<div style='float:left; width: 400px; height:margin-right: 10px;'>
<table style='width: 100%; height: 175px; border: 1px solid #000000; padding: 3px; font-size: 90%; font-family: Arial, Helvetica, sans-serif;'>
<tr>
<th align='left'></th>
<th align='left'></th>
</tr>
<tr>
<td width='30%'>Main Client:</td>
<td width='65%' align='left' style='border: 1px solid #000000;'>".$row['main_client']."</td>
</tr>
<tr>
<td width='30%'>Postal Address:</td>
<td width='65%' align='left' style='border: 1px solid #000000;'>".$row['postal_address']."</td>
</tr>
<tr>
<td width='30%'>Contact Person:</td>
<td width='65%' align='left' style='border: 1px solid #000000;'>".$row['contact_person']."</td>
</tr>
<tr>
<td width='30%'>Telephone / Cell:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['cell_offc']."</td>
</tr>
<tr>
<td width='30%'>Office Location:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['office_loc']."</td>
</tr>
<tr>
<td width='30%'>Email Address:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['email_addr']."</td>
</tr>
<tr>
<td width='30%'>Job Title:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['job_title']."</td>
</tr>
</table>
</div>
<div style='float:right; width: 40%; border: '>
<table style='width: 100%; height: 175px; border: 1px solid #000000; padding: 3px; font-size: 90%; font-family: Arial, Helvetica, sans-serif;'>
<tr>
<th align='left'></th>
<th align='left'></th>
</tr>
<tr>
<td colspan='2' align='center' style='background: #000000; color: #ffffff;'>Customer Tax Information:</td>
</tr>
<tr>
<td>TIN#:</td>
<td align='left' style='border: 1px solid #000000;' >".$row['clnt_tin']."</td>
</tr>
<tr>
<td>VRN#</td>
<td align='left' style='border: 1px solid #000000;' >".$row['clnt_vrn']."</td>
</tr>
<tr>
<td>VAT Exempted:</td>
<td align='left' style='border: 1px solid #000000;'>".$row['vat_expt']."</td>
</tr>
<tr>
<td>Exemption Cert</td>
<td align='left' style='border: 1px solid #000000;' >".$row['expt_cert']."</td>
</tr>
<tr>
<td colspan='2' align='center' style='background: #000000; color: #ffffff;'>Our Tax Information:</td>
</tr>
<tr>
<td>TIN#:</td>
<td align='left' style='border: 1px solid #000000;'>".$row['our_tin']."</td>
</tr>
<tr>
<td>VRN#:</td>
<td align='left' style='border: 1px solid #000000;' >".$row['our_vrn']."</td>
</tr>
</table>
</div>
<div style='clear:both;'>
</div>
<div>
</div>
</div>";
$sample .= "<table style='width: 100%; font-family: Arial, Helvetica, sans-serif; ' >
<tr>
<th align='center' style='border: 1px solid #000000;' >Requested Date:</th>
<th align='center' style='border: 1px solid #000000;'>Requested By:</th>
<th align='center' style='border: 1px solid #000000;'>Sales Person:</th>
</tr >
<tr>
<td align='center' style='border: 1px solid #000000;'>".$row['date_created']."</td>
<td align='center' style='border: 1px solid #000000;'>".$row['prepared_by']."</td>
<td align='center' style='border: 1px solid #000000;'>".$row['sales_person']."</td>
</tr>
</table>";
$idfk = $row['inv_code']; // id for viewing
$subtotl = $row['sub_totl']; // id for viewing
$vattotl = $row['vat_percent']; // id for viewing
$grandtotl = $row['grand_total']; // id for viewing
$dis_perc_sub = $row['dis_perc_sub']; // id for viewing
$lpouser = $row['lpo_user']; // id for viewing
$lpostatus = $row['lpo_status']; // id for viewing
$servername = "...";
$username = "...";
$password = "...";
$dbname = "....";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM itemsinv WHERE invidfk='$idfk' ORDER BY ln_no ASC";
$result = mysqli_query($conn, $sql);
$count = 0;
$sample .= "<table cellspacing='1' cellpadding='1' style='width:100%; border: 1px solid black; font-family: Arial, Helvetica, sans-serif; margin-top: 20px 0 0 0;
th, td { padding: 5px;}' >
<tr>
<th align='center' style='background: #000000; color: #ffffff; '>No</th>
<th align='center' style='background: #000000; color: #ffffff; '>Product Details</th>
<th align='center' style='background: #000000; color: #ffffff; '>Price</th>
<th align='center' style='background: #000000; color: #ffffff; '>Qty</th>
<th align='center' style='background: #000000; color: #ffffff; '>Total</th>
</tr>";
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$count++;
$sample .= "<tr>
<td style='border: 1px solid black;'>" .$count. "</td>
<td style='border: 1px solid black;'><b>" . $row['productname']. "</b><br>" . $row['particulars']. "</td>
<td style='border: 1px solid black;'>". $row['price']. "</td>
<td style='border: 1px solid black;'>". $row['qty']. "</td>
<td style='border: 1px solid black;'>". $row['item_total']. "</td>
</tr>";
}
} else {
echo "0 results";
}
$sample .= "<tr><td align='right' colspan='4'><b>Sub Total:</b></td><td align='left' style='border: 1px solid #000000;'>".$subtotl."</td></tr>";
$sample .= "<tr><td align='right' colspan='4'><b>VAT Total:</b></td><td align='left' style='border: 1px solid #000000;'>".$vattotl."</td></tr>";
$sample .= "<tr><td align='right' colspan='4'><b>Discount %:</b></td><td align='left' style='border: 1px solid #000000;'>".$dis_perc_sub."</td></tr>";
$sample .= "<tr ><td align='right' colspan='4'><b>Grand Total:</b></td><td align='left' style='border: 1px solid #000000;'>".$grandtotl."</td></tr>";
$sample .= "</table>";
$sample .= "<br><b style='font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>Please read our terms and conditions by visiting our website. http://signindustries.co.tz</b>";
mysqli_close($conn);
// create pdf of invoice
$invoiceFileName = 'Invoice-'. $row["contact_name"]. '.pdf';
require_once 'dompdf/src/Autoloader.php';
Dompdf\Autoloader::register();
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml(html_entity_decode($sample));
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream($invoiceFileName, array("Attachment" => false));
?>
Error log below
Stack trace:
#0 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4870): Imagick->writeimage('/tmp/cpdf_img_e...')
#1 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4984): Cpdf->addImagePngAlpha('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562, 6)
#2 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Adapter/CPDF.php(864): Cpdf->addPngFromFile('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562)
#3 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer/Image.php(110): Dompdf\Adapter\CPDF->image('/home/crmsignin...', 45.265748031496, 68.848148031496, 187.5, 35.112359550562, 'normal')
#4 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer.php(293): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\I in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php on line 4870
[06-Jul-2020 13:58:06 UTC] PHP Warning: Version warning: Imagick was compiled against Image Magick version 1650 but version 1654 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
[06-Jul-2020 13:58:06 UTC] PHP Fatal error: Uncaught ImagickException: WriteBlob Failed `/tmp/cpdf_img_QpfKj7.png' # error/png.c/MagickPNGErrorHandler/1755 in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php:4870
Stack trace:
#0 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4870): Imagick->writeimage('/tmp/cpdf_img_Q...')
#1 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4984): Cpdf->addImagePngAlpha('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562, 6)
#2 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Adapter/CPDF.php(864): Cpdf->addPngFromFile('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562)
#3 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer/Image.php(110): Dompdf\Adapter\CPDF->image('/home/crmsignin...', 45.265748031496, 68.848148031496, 187.5, 35.112359550562, 'normal')
#4 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer.php(293): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\I in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php on line 4870
[06-Jul-2020 13:59:05 UTC] PHP Warning: Version warning: Imagick was compiled against Image Magick version 1650 but version 1654 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
[06-Jul-2020 13:59:05 UTC] PHP Fatal error: Uncaught ImagickException: WriteBlob Failed `/tmp/cpdf_img_0wDRir.png' # error/png.c/MagickPNGErrorHandler/1755 in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php:4870
Stack trace:
#0 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4870): Imagick->writeimage('/tmp/cpdf_img_0...')
#1 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4984): Cpdf->addImagePngAlpha('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562, 6)
#2 /home/host/public_html/crm/admins/dompdf/src/Adapter/CPDF.php(864): Cpdf->addPngFromFile('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562)
#3 /home/host/public_html/crm/admins/dompdf/src/Renderer/Image.php(110): Dompdf\Adapter\CPDF->image('/home/crmsignin...', 45.265748031496, 68.848148031496, 187.5, 35.112359550562, 'normal')
#4 /home/host/public_html/crm/admins/dompdf/src/Renderer.php(293): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\I in /home/host/public_html/crm/admins/dompdf/lib/Cpdf.php on line 4870

CSS Changing The Look of A Table

I have a table on my website which contains the columns: User, Title, Description, Join, Update, Delete.
The "User" column's width is way too big as well as the "Title" column. I need help with CSS to set them to something smaller without affecting the width of the other columns as they are perfect as is.
My Code:
<?php
echo "<table>
<tr>
<th>User</th>
<th>Title</th>
<th>Description</th>
<th></th>
<th>Join</th>
<th>Update</th>
<th>Delete</th>
</tr>";
while ($record = mysql_fetch_array($myData))
{
echo "<form action=findGroup.php method=post>";
echo "<div class=joinLink>";
echo "<tr>";
echo "<td>" . "<input type=text name=name value='" . $record['form_user'] . "'/> </td>";
echo "<td>" . "<input type=text name=name value='" . $record['form_name'] . "'/> </td>";
echo "<td>" . "<input type=text name=description value='" . $record['form_description'] . "'/> </td>";
echo "<td>" . "<input type=hidden name=hidden value='" . $record['form_id'] . "'/></td>";
echo "<td><a class=joinLink type=text name=join href='http://localhost:3000'>Join</a></td>";
echo "<td>" . "<input type=submit name=update value='Update" . "'/> </td>";
echo "<td>" . "<input type=submit name=delete value='Delete" . "'/> </td>";
echo "</tr>";
echo "</div>";
echo "</form>";
}
echo "</table>";
CSS:
table {
width: 100%;
font: 17px/1.5 Arial, Helvetica,sans-serif;
text-align: centre;
align: centre;
}
input {
width: 100%;
font: 13px/1.5 Arial, Helvetica,sans-serif;
text-align: centre;
align: centre;
height: auto;
overflow: hidden;
}
th {
align: centre;
text-align: centre;
background-color: #4D5960;
color: white;
}
tr {
background-color: #f2f2f2
}
input[type="text"]{
width:100% !important;
line-height:30px;
box-sizing:border-box;
}
a[type="text"]{
width:100% !important;
line-height:30px;
box-sizing:border-box;
}
You can use width property to fix the width of your columns. You can apply width in html directly or using css
HTML
<td width="20%">content</td>
<th width="20%">content</th>
CSS
.custom-class{
width: 20%;
}
<th class="custom-class"></th>
<td class="custom-class"></td>
If you don't mind I would suggest some changes, see below. Check if the form action is either join, update or delete to perform the action. About the data structure you receive when the form is submitted check out the var_dump($_POST); part
PHP:
<?php
var_dump($_POST);
?>
CSS:
table {
width: 100%;
font: 17px/1.5 Arial, Helvetica,sans-serif;
}
input[type="text"] {
width: 100%;
font: 13px/1.5 Arial, Helvetica,sans-serif;
text-align: center;
box-sizing: border-box;
padding: 6px 13px;
}
button {
width: 100%;
font: 13px/1.5 Arial, Helvetica,sans-serif;
text-align: center;
box-sizing: border-box;
padding: 6px 13px;
}
thead th {
align: center;
text-align: center;
background-color: #4D5960;
color: #ffffff;
}
tbody td {
align: center;
text-align: center;
background-color: #f2f2f2;
}
HTML/PHP:
<form action="index.php" method="POST" enctype="application/x-www-form-urlencoded">
<table>
<thead>
<tr>
<th class="col-name">User</th>
<th class="col-title">Title</th>
<th class="col-description">Description</th>
<th class="col-join">Join</th>
<th class="col-update">Update</th>
<th class="col-delete">Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ([0, 1, 2, 3] as $row) : ?>
<tr>
<td class="col-name">
<input type="hidden" name="user[id][]" value="">
<input type="text" name="user[name][]" value="" size="10">
</td>
<td class="col-title">
<input type="text" name="user[title][]" value="" size="10">
</td>
<td class="col-description">
<input type="text" name="user[description][]" value="" size="10">
</td>
<td class="col-join">
<button type="submit" name="action" value="join">Join</button>
</td>
<td class="col-update">
<button type="submit" name="action" value="update">Update</button>
</td>
<td class="col-delete">
<button type="submit" name="action" value="delete">Delete</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
it seems that there is no problem, everything is the same
table {
width: 100%;
font: 17px/1.5 Arial, Helvetica,sans-serif;
text-align: center;
align: center;
}
input {
width: 100%;
font: 13px/1.5 Arial, Helvetica,sans-serif;
text-align: center;
align: center;
height: auto;
overflow: hidden;
}
th {
align:center;
text-align: center;
background-color: #4D5960;
color: white;
}
tr {background-color: #f2f2f2}
input[type="text"]{width:100% !important; line-height:30px; box-sizing:border-box;}
a[type="text"]{width:100% !important; line-height:30px; box-sizing:border-box;}
https://jsfiddle.net/1qy5v05p/6/
you can also use Bootstrap 4, maybe it will be better https://www.w3schools.com/bootstrap4/bootstrap_forms.asp
There are bunch of jQuery table plugins. Check this out.
My favourites are DataTables, x-Editable and Bootgrid. There are also open sources, you can see them with their Github repo.

How to get data from form and make and array

I am just making a railway reservation project to my college therefor I have to get passenger details and make a 2d array and send it to another page to show the summary but I just don't know how to do that.
my code is
<?php
include('connection.php');
session_start();
$train_number = $_GET['train_number'];
$train_name = $_GET['train_name'];
$coachid = $_GET['coachid'];
$date = $_SESSION['date'];
$day = $_SESSION['day'];
$coachtype = $_SESSION['coachtype'];
$useremail = $_SESSION['useremail'];
if($_SERVER['REQUEST_METHOD']='POST')
{
if(!empty($_POST['proceed']))
{
$i = 1;
while($i<7)
{
"What to write here";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Buy Tickets </title>
<link rel="stylesheet" href="css.css">
</head>
<body>
<div class="wrapper">
<div class="header">
<img src="banner.jpg" height="100%" width="100%"/>
</div>
<div class="navbar">
<ul>
<li>Dashboard </li>
<li>Buy Ticket </li>
<li>Cancel ticket</li>
<li>Edit Profile</li>
<li id="last">Logout</li>
</ul>
</div>
<div>
<?php
echo "<h4 align='center'><u>Booking for </u></h4>";
echo "<table align='center'>
<thead>
<tr style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Train Number </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Train name </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Date </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Coach type </th>
</tr>
</thead>";
echo "<tr>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$train_number."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$train_name."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$date."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$coachtype."</td>";
echo "</tr>";
echo "</table>";
echo "<h4 align='center'><u>Passenger details </u></h4>";
echo "<table align='center'>
<thead>
<tr style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> No </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Passenger Name </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Age </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Gender type </th>
</tr>
</thead>";
$iforlist = 1;
while($iforlist<7)
{
echo "<form method='post'>";
echo "<tr>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$iforlist."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'><input type='text' name='passenger_name.".$iforlist."' value='' placeholder='Enter name '></td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'><input type='number' name='passenger_age.".$iforlist."' value='' max='100' min='1' placeholder='Enter passenger age '></td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'><select name='passenger_gender.".$iforlist."'>
<option value='Male'>Male</option>
<option value='Female'>Female</option>
</select></td></td>";
echo "</tr>";
$iforlist++;
}
echo "</table>";
echo "<div align='center' style='margin-top:10px;'><input type='submit' align='center' name='proceed' value='Proceed' style='width:100px;height:40px;' placeholder='Enter name '></div>";
echo "</form>";
?>
</div>
</div>
</body>
</html>
So, tell me how can i make fetch data if only 2 or 3 field are filled and make a 2d array of it.
if you want any other information i'll give you..
Here is an example of how to use 2D Arrays in PHP
$cars = array
(
array("Volvo",22,18),
array("BMW",15,13),
array("Saab",5,2),
array("Land Rover",17,15)
);
Now to access the data, you must specify the row and column:
<?php
echo $cars[0][0].": In stock: ".$cars[0][1].", sold: ".$cars[0][2].".<br>";
echo $cars[1][0].": In stock: ".$cars[1][1].", sold: ".$cars[1][2].".<br>";
echo $cars[2][0].": In stock: ".$cars[2][1].", sold: ".$cars[2][2].".<br>";
echo $cars[3][0].": In stock: ".$cars[3][1].", sold: ".$cars[3][2].".<br>";
?>
In this case:
array("Volvo",22,18)
That is a single row (0) and it has three columns (Volvo at row=0 column=0, 22 at row=0 colum=1, etc)
I took the example from here: https://www.w3schools.com/php/php_arrays_multi.asp
Let me know if this helps.

PHP alternating colors

$dbc = mysql_connect('localhost','root','') or die (mysql_error());
mysql_select_db('payroll') or die (mysql_error());
$sql = "SELECT * FROM employee ORDER BY employee_id DESC";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo "
<tr>
<td style=\"padding-left: 20px; border-bottom: 1px solid #999; border-right: 1px solid #999;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #999; border-right: 1px solid #999; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
}
I wanted to add an alternating color in the loop. what code should I add?
$rowCount = 0;
$colorOne = '#ffffff';
$colorTwo = '#f3f3f3';
while($row = mysql_fetch_array($result)){
$rowColor = ($rowCount % 2) ? $colorOne : $colorTwo;
echo "<element bgcolor='$rowColor'></element>";
$rowCount++;
}
Edited after #Jayrox comment.
Use CSS classes instead of inline styles. They're easier to manipulate. Then style the .myclass_row_0 and .myclass_row_1 in your CSS for the alternate row color as well as .col1 and .col2 for the column styles.
$c=1; // or 0 (added after deceze's comment)
while($row = mysql_fetch_array($result)) {
$c=1-$c; // magic!
echo "
<tr class=\"myclass_row_$c\">
<td class=\"col1\">".$row['first_name']." ".$row['last_name']."</td>
<td class=\"col2\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
}
Or using inline styles:
$colors = array('#ffffff','#f3f3f3');
$c=1;
while($row = mysql_fetch_array($result)) {
$c=1-$c;
echo "
<tr style=\"background-color:{$colors[$c]};\">
<!-- tds here -->
</tr>
";
}
Or using preset classes:
$styles = array('odd','even');
$c=1;
while($row = mysql_fetch_array($result)) {
$c=1-$c;
echo "
<tr class=\"{$styles[$c]}\">
<!-- ... -->
</tr>
";
}
There are already a lot of solutions, but this one use only two lines of css.
You can set specific css on even and odd rows:
tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}
Usually, I will declare an index(int) value and increment for each time through the loop. Then do a check to see if index mod 2 = 1. If so, then output a tr with the style that you want to apply to show an alternating row.
$color = 0;
while($row = mysql_fetch_array($result)) {
if($color % 2 == 1){
echo "<tr>";
}else{
echo "<tr class=\"altRow\">";
}
echo "
<td style=\"padding-left: 20px; border-bottom: 1px solid #999; border-right: 1px solid #999;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #999; border-right: 1px solid #999; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
$color++;
}
As it's bumped already, here is my 5 cents.
7 answers and not a single one using templates.
We can write a thousand articles of the templates necessity, but such an examples will always win.
So, based on the OP's code and stagas' answer:
business logic part:
$c = 1;
$DATA = array();
$sql = "SELECT * FROM employee ORDER BY employee_id DESC";
$result = mysql_query($sql) or trigger_error(mysql_error().$sql);
while($row = mysql_fetch_array($result)) {
$row['c'] = $c=1-$c;
$DATA[] = $row;
}
and template part:
<tr class="myclass_row_<?=$row['$c']?>">
<td class="col1"><?=$row['first_name']?> <?=$row['last_name']?></td>
<td class="col2">
<input type="button" name="edit" value="Edit" class="selbtn"> <input type="button" name="delete" value="Delete" class="selbtn">
</td>
</tr>
$color = 1;
while($row = mysql_fetch_array($result)) {
if($color == 1){
echo "
<tr>
<td style=\"padding-left: 20px; border-bottom: 1px solid #999; border-right: 1px solid #999;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #999; border-right: 1px solid #999; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
$color = 2;
}
else
{
echo "
<tr>
<td style=\"padding-left: 20px; border-bottom: 1px solid #555; border-right: 1px solid #555;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #555; border-right: 1px solid #555; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
}
$color = 1;
}
// here it is in less code
<?php
$dbc = mysql_connect('localhost','root','') or die (mysql_error());
mysql_select_db('payroll') or die (mysql_error());
$sql = "SELECT * FROM employee ORDER BY employee_id DESC";
$result = mysql_query($sql);
$colors = array('FFF', '000000'); // valid hex colors
$numOfColors = sizeOf($colors); $i = 0
while($row = mysql_fetch_array($result)) {
$i++;if($i>$numOfColors){$i=0;}
?>
<tr>
<td style="padding-left: 20px; border-bottom: 1px solid #<?=$colors[$i]?>; border-right: 1px solid #<?=$colors[$i]?>;"> <?=$row['first_name']?> <?=$row['last_name']?> </td>
<td style="text-align: center; border-bottom: 1px solid #<?=$colors[$i]?>; border-right: 1px solid #<?=$colors[$i]?>; padding-top: 2px ; padding-bottom: 3px ;"><input type="button" name="edit" value="Edit" class="selbtn"> <input type="button" name="delete" value="Delete" class="selbtn"></td>
</tr>
<?php
}
?>
Just keep track whether it is an alternating row with a Boolean. Initialize it to false before your loop, not it for each iteration, then you can set the row style based on its value. Something like:
...
$isAlternatingRow = false;
while($row = mysql_fetch_array($result)) {
echo "
<tr class=\"" . $isAlternatingRow ? "defaultRow" : "alternatingRow" . "\">
<td style=\"padding-left: 20px; border-bottom: 1px solid #999; border-right: 1px solid #999;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #999; border-right: 1px solid #999; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
$isAlternatingRow = !($isAlternatingRow);
}
Then just define styles for tr.defaultRow td and tr.alternatingRow td.
$class="even"
while($row = mysql_fetch_array($result))
{
if($class == "even")
{
echo "<tr class='$class'>";
$class="odd"
}
else
{
echo "<tr class='$class'>";
$class="even";
}
...
}
I did it like this:
Remember to add a CSS class called "even", with styling of course.
<?php
include 'connect.php';
echo "<table id='hor-zebra'>";
$i = 0;
while($row = mysql_fetch_array($result))
{
if($i % 2 == 0)
{
echo "<tr class='even'>";
echo "<td>" . $row['something'] . "</td>";
echo "</tr>";
}
else
{
echo "<tr>";
echo "<td>" . $row['something'] . "</td>";
echo "</tr>";
}
$i++;
}
echo "</table>";
mysql_close($con);
?>
Using predefined color outside the loop.
$rowCount = 0;
$color = array('#ffffff','#f3f3f3');
while($row = mysql_fetch_array($result)){
$i = ($rowCount % 2);
echo "<element bgcolor='".$color["$i"]."'></element>";
$rowCount++;
}

Categories