PHP Form result to Dompdf PDF - php

I am trying to export the results of a form generated by PHP to PDF through DOMPDF. But its generating a blank page. May be the generated HTML has some issues.
PHP Script is as follows. Iam just pasting the HTML output here since the PHP file is long and has lots of functions. so i guess its a problem with HTML formatting:
<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
?>
<!DOCTYPE html>
<head>
<title>Country Language</title>
</head>
<body>
<?php ob_start(); ?>
<form>
<table border="1"><tr><td><b>Countries Selected</b></td><td><b>Details</b></td><td><b>Amount</b></td></tr>
<tr>
<td rowspan='8'><h2>Australia</h2></td>
</tr>
<tr>
<td> Z</td>
<td>3</td>
</tr>
<tr>
<td> Entity</td>
<td> </td>
</tr>
<tr>
<td> N</td>
<td> 0</td>
</tr>
<tr>
<td>English to English</td>
<td> </td>
</tr>
<tr>
<td> X</td>
<td> 1</td>
</tr>
<tr>
<td> Y</td>
<td> 2</td>
</tr>
<tr>
<td><strong>TOTAL PATENT FEE</strong></td>
<td><b> USD 1400.45</b></td>
</tr>
<tr>
<td rowspan='8'><h2>India</h2></td>
</tr>
<tr>
<td> Z</td>
<td>3</td>
</tr>
<tr>
<td> Entity</td>
<td> Micro</td>
</tr>
<tr>
<td> N</td>
<td> 1</td>
</tr>
<tr>
<td>Arabic to English</td>
<td> </td>
</tr>
<tr>
<td> X</td>
<td> 1</td>
</tr>
<tr>
<td> Y</td>
<td> 2</td>
</tr>
<tr>
<td><strong>TOTAL PATENT FEE</strong></td>
<td><b> USD 315.45</b></td>
</tr>
</table>
<?php
if ( isset( $_GET['pdf'] ) ) {
$html = ob_get_contents();
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("the_inquiry.pdf");
}
?>
<div class="shouldPrintToPDF">
Open as PDF
</div>
</form>
</body>
</html>
THE PHP SCRIPT IS AS FOLLOWS:
<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
if (isset($_GET['pdf'])) {
ob_start();
}
else {
?>
<!DOCTYPE html>
<head>
<title>Country Language</title>
</head>
<body>
<form>
<?php
if(isset($_POST['submit'])) {
$language_selected = $_POST['language'];
$claims_selected = $_POST['claims'];
$pages_selected = $_POST['pages'];
$totalwords_selected = $_POST['totalwords'];
$claims_selected = $_POST['claims'];
$entity_selected1 = $_POST['entity_selected'];
//echo '<div class="container">';
echo '<form>';
echo '<table border="1">';
echo '<tr><td><b>Countries Selected</b></td><td><b>Fee Details</b></td><td><b>Amount</b></td></tr>';
foreach ($_POST['check_list'] as $key => $country_checked) {
if(!empty($_POST['entity_selected'][$key])) {
$entity_selected = $_POST['entity_selected'][$key];
} else {
$entity_selected = '';
}
$sql_db = mysqli_query($conn,"SELECT id, country, language, entity FROM country_languages where country = '$country_checked' ");
//$row_db = mysqli_fetch_assoc($sql_db);
while($row_db = mysqli_fetch_array($sql_db)) {
$id = $row_db["id"];
$country = $row_db["country"];
$language = $row_db["language"];
$entity = $row_db["entity"];
if ($language_selected == $language) {
$Z = '0';
} else {
$Z = $totalwords_selected;
}
if ($entity_selected =='') {
$N = '0';
} else if ($entity_selected == 'Micro') {
$N = '1';
} else if (($entity_selected == 'Small') AND ($country_checked == 'India')) {
$N = '2.2';
} else if (($entity_selected == 'Small') AND ($country_checked !== 'India')) {
$N = '2';
} else if (($entity_selected == 'Large') AND ($country_checked == 'India')) {
$N = '4.4';
} else if (($entity_selected == 'Large') AND ($country_checked == 'Philippines')) {
$N = '5.5';
} else if (($entity_selected == 'Large') AND ($country_checked !== 'Philippines') AND ($country_checked !== 'India')) {
$N = '4';
} else {
$N = '0';
}
$X = $claims_selected;
$Y = $pages_selected;
if ($country_checked == 'USA') {
$result = (430 + 25 * ($X - 20) + 200 * (($Y - 100) / 50 + (1 - ($Y - 100) / 50))) * $N + 0.15 * $Z + 750;
} else {
$result = 'Not able to fetch data.';
}
?>
<tr>
<td rowspan='8'><h2><?php echo $country_checked; ?></h2></td>
</tr>
<tr>
<td> Z</td>
<td><?php echo $Z; ?></td>
</tr>
<tr>
<td> Entity</td>
<td> <?php echo $entity_selected; ?></td>
</tr>
<tr>
<td> N</td>
<td> <?php echo $N; ?></td>
</tr>
<tr>
<td><?php echo $language_selected; ?> to <?php echo $language; ?></td>
<td> </td>
</tr>
<tr>
<td> X</td>
<td> <?php echo $X; ?></td>
</tr>
<tr>
<td> Y</td>
<td> <?php echo $Y; ?></td>
</tr>
<tr>
<td><strong>TOTAL PATENT FEE</strong></td>
<td><b> USD <?php echo number_format((float)$result, 2, '.', ''); ?></b></td>
</tr>
<?php
} // END WHILE LOOP
} //END FOR LOOP
echo '</table>';
}
?>
<?php
if (isset($_GET['pdf'])) {
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("the_inquiry.pdf");
}
else {
?>
<div class="shouldPrintToPDF">
Open or save as PDF
</div>
</form>
</body>
</html>
<?php } }?>

The problem is that you output HTML content even when the pdf query string exists in the URL. The generated PDF will be mixed with HTML so it becomes invalid. You shouldn't send any HTML code to the browser when you send the PDF. Here is a possible solution with conditionals:
<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
if (isset($_GET['pdf'])) {
ob_start();
}
else {
?>
<!DOCTYPE html>
<head>
<title>Country Language</title>
</head>
<body>
<form>
<?php } ?>
<table border="1"><tr><td><b>Countries Selected</b></td><td><b>Details</b></td><td><b>Amount</b></td></tr>
<tr>
<td rowspan='8'><h2>Australia</h2></td>
</tr>
<tr>
<td> Z</td>
<td>3</td>
</tr>
<tr>
<td> Entity</td>
<td> </td>
</tr>
<tr>
<td> N</td>
<td> 0</td>
</tr>
<tr>
<td>English to English</td>
<td> </td>
</tr>
<tr>
<td> X</td>
<td> 1</td>
</tr>
<tr>
<td> Y</td>
<td> 2</td>
</tr>
<tr>
<td><strong>TOTAL PATENT FEE</strong></td>
<td><b> USD 1400.45</b></td>
</tr>
<tr>
<td rowspan='8'><h2>India</h2></td>
</tr>
<tr>
<td> Z</td>
<td>3</td>
</tr>
<tr>
<td> Entity</td>
<td> Micro</td>
</tr>
<tr>
<td> N</td>
<td> 1</td>
</tr>
<tr>
<td>Arabic to English</td>
<td> </td>
</tr>
<tr>
<td> X</td>
<td> 1</td>
</tr>
<tr>
<td> Y</td>
<td> 2</td>
</tr>
<tr>
<td><strong>TOTAL PATENT FEE</strong></td>
<td><b> USD 315.45</b></td>
</tr>
</table>
<?php
if (isset($_GET['pdf'])) {
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("the_inquiry.pdf");
}
else {
?>
<div class="shouldPrintToPDF">
Open as PDF
</div>
</form>
</body>
</html>
<?php } ?>
You only generate the table when a POST request was made and the data is available to generate the table. When you click on the PDF link a GET request is made. You can solve it by sending and receiving data with GET instead of POST. (eg.: $_POST['language'] => $_GET['language']). Another solution is to replace the PDF link with a form (it can be an invisible form with hidden input fields) that sends the necessary data. You should also delete other <form> and </form> tags from the page(I think they are unnecessary).
<?php
function repopulate($field) {
if (isset($_POST[$field])) {
echo htmlspecialchars($_POST[$field]);
}
}
?>
<div class="shouldPrintToPDF">
<form method="post" action="?pdf=1">
<input type="hidden" name="language" value="<?php repopulate('language'); ?>">
<!-- Add all your fields (claims, pages...) here and use the repopulate function -->
<button name="submit" type="submit">Open or save as PDF</button>
</form>
</div>
I hope it helps you!

Related

How do I fetch a table inside an entry in PHP firebase?

After successfully inputting data inside a key, I am now facing the problem of trying to display it.
this is the code that I've been trying and modifying to try and fetch it but to still to no avail
<tr>
<th>Course Code</th>
<th>Discriptive Title</th>
<th>Unit</th>
<th>Pre-Requisite</th>
<th>Grade</th>
</tr>
<?php
include('dbcon.php');
if(isset($_GET['id']))
{
$key_child = $_GET['id'];
$ref_table = 'User'.$key_child.'/Grades/1st Year/1st Sem';
$fetchdata = $database->getReference($ref_table)->getChild($key_child)->getValue();
if($fetchdata > 0)
{
$i = 0;
?>
<input type="hidden" name = "id" value = "<?=$key_child;?>">
<?php
foreach($fetchdata as $key_child => $row)
{
?>
<tr>
<td> <?= $row['Course_Code'];?> </td>
<td> <?= $row['Desc_title'];?> </td>
<td> <?= $row['Unit'];?> </td>
<td> <?= $row['Pre-Req'];?> </td>
<td> <?= $row['Grade'];?> </td>
</td>
</tr>
<?php
}
}
else
{
?>
<td colspan = "5"> Nothing Found </td>
<?php
}
}
else
{
?>
<td colspan = "5"> No Record found </td>
<?php
}
It is displaying the "Nothing Found" when I execute it even though there are data in the database.
And this is the code that I initially tried for some context.
<tr>
<th>Course Code</th>
<th>Discriptive Title</th>
<th>Unit</th>
<th>Pre-Requisite</th>
<th>Grade</th>
</tr>
$key_child = $_GET['id'];
$ref_table = 'User'.$key_child.'/Grades/1st Year/1st Sem';
$getdata = $database->getReference($ref_table)->getChild($key_child)->getValue();
if($getdata > 0)
{
?>
<input type="hidden" name = "id" value = "<?=$key_child;?>">
<tr>
<td> <?= $row['Course_Code'];?> </td>
<td> <?= $row['Desc_title'];?> </td>
<td> <?= $row['Unit'];?> </td>
<td> <?= $row['Pre-Req'];?> </td>
<td> <?= $row['Grade'];?> </td>
</td>
</tr>
If $key_child is 5nKX..., then you're missing a / after User in this code:
$ref_table = 'User'.$key_child.'/Grades/1st Year/1st Sem'
So to fix that problem:
$ref_table = 'User/'.$key_child.'/Grades/1st Year/1st Sem'
// 👆

Superglobal GET using PHP

I am new to php and I couldn't find the answer on stack. I am experimenting and trying to figure out how I can use the superglobal GET to display an image and also change the *count depending on how the user modifies it in the URL.
I would like to change the Beach image count times.
So the URL would look something like:
website.com/table?beach_image=2&count=4
and would display the beach image #2, 4 times:
bathing suit
<?php
$beach = ['sunglasses.jpg','suncreen.jpg','bathing-suit.jpg','hat.jpg'];
$count = 1;
$beach_image = filter_input(INPUT_GET,"beach_image");
?>
for my html:
<table>
<tr>
<th>Beach Image</th>
<th>Beach</th>
</tr>
<tr>
<td>0</td>
<td>Sunglasses</td>
</tr>
<tr>
<td>1</td>
<td>Sunscreen</td>
</tr>
<tr>
<td>2</td>
<td>Bathing Suit</td>
</tr>
<tr>
<td>3</td>
<td>Hat</td>
</tr>
</table>
<div>
<img src="images/<?= $beach[$beach_image]?>">
</div>
You can do it like below
<?php
$beach = ['sunglasses.jpg','suncreen.jpg','bathing-suit.jpg','hat.jpg'];
$keysArr = array_fill(0,count($beach),0);//array_combine(array_keys($beach),array_fill(0,count($beach),0));
$beach_image = filter_input(INPUT_GET,"beach_image");
$count = filter_input(INPUT_GET,"count");
$keysArr[$beach_image] = $count;
?>
<table>
<tr>
<th>Beach Image</th>
<th>Beach</th>
</tr>
<tr>
<td><?php echo $keysArr[0] ;?></td>
<td>Sunglasses</td>
</tr>
<tr>
<td><?php echo $keysArr[1] ;?></td>
<td>Sunscreen</td>
</tr>
<tr>
<td><?php echo $keysArr[2] ;?></td>
<td>Bathing Suit</td>
</tr>
<tr>
<td><?php echo $keysArr[3] ;?></td>
<td>Hat</td>
</tr>
</table>
<div>
<?php for($i=1;$i=$count;$i++){?>
<img src="images/<?= $beach[$beach_image]?>">
<?php }?>
</div>

SQL query fails in prod environment on IIS but works in test environment running Apache

I'm having a bit of an issue with quires failing when I upload to the live environment while they are fully functional in the test environment, I'm at a loss at this point about where the error may be so I finally broke down and decided to ask those of stack overflow that may be much more skilled than myself if there's something I've missed. The quires look at serial number information from two different tables to pull system specs and any hard drive information associated with the parent serial
<?php
$Dev_HDD = 0;
$con=mysqli_connect("localhost","username","user_password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST["serial"]))
{
$SerialNumber = $_POST["serial"];
$sql ="SELECT system.Manufacturer, system.Model, system.SerialNumber, system.Processor, system.Memory FROM system WHERE SerialNumber = '" .$SerialNumber. "'" ;
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
$System_Manufacturer = $row[0];
$System_Model = $row[1];
$System_SerialNumber = $row[2];
$System_Processor = $row[3];
$System_Memory = $row[4];
?>
<table border="0" height="100%" width="100%" align="left" valign="top">
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2" valign="top">System Summary:</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>System Manufacturer</td>
<td>
<?php echo $System_Manufacturer; ?>
</td>
</tr>
<tr>
<td>System Model:</td>
<td>
<?php echo $System_Model; ?>
</td>
</tr>
<tr>
<td valign="top">System Serial Number</td>
<td valign="top">
<?php echo $System_SerialNumber; ?>
</td>
</tr>
<tr>
<td valign="top">System Processor</td>
<td valign="top">
<?php echo $System_Processor; ?>
</td>
</tr>
<tr>
<td valign="top">System Memory</td>
<td valign="top">
<?php echo $System_Memory; ?>
</td>
</tr>
<?php
}
// Free result set
mysqli_free_result($result);
}
else
{
echo "The serial number specified could not be located<br>";
}
$sql ="SELECT device.recid, device.Manufacturer, device.Model, device.SerialNumber, device.Capacity, device.RPM, device.ErasureMethod, device.ErasureResults FROM device WHERE SystemSerialNumber = '" . $System_SerialNumber . "'" ;
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
$Dev_Recid = $row[0];
$Dev_Manufacturer = $row[1];
$Dev_Model = $row[2];
$Dev_DeviceSerialNumber = $row[3];
$Dev_Capacity = $row[4];
$Dev_RPM = $row[5];
$Dev_ErasureMethod = $row[6];
$Dev_ErasureResults = $row[7];
?>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2" valign="top">Storage Summary(<?php echo $Dev_HDD = $Dev_HDD + 1; ?>):</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>Hard Drive Manufacturer</td>
<td>
<?php echo $Dev_Manufacturer; ?>
</td>
</tr>
<tr>
<td>Hard Drive Model:</td>
<td>
<?php echo $Dev_Model; ?>
</td>
</tr>
<tr>
<td valign="top">Serial Number Lookup</td>
<td valign="top">
<?php echo $Dev_DeviceSerialNumber; ?>
</td>
</tr>
<tr>
<td valign="top">Hard Drive Capacity</td>
<td valign="top">
<?php echo $Dev_Capacity; ?>
</td>
</tr>
<tr>
<td valign="top">Hard Drive Speed</td>
<td valign="top">
<?php echo $Dev_RPM; ?>
</td>
</tr>
<tr>
<td>Erasure Method:</td>
<td>
<?php echo $Dev_ErasureMethod; ?>
</td>
</tr>
<tr>
<td>Erasure Results:</td>
<td>
<?php echo $Dev_ErasureResults; ?>
</td>
</tr>
<tr>
<td>Parent Serial Number:</td>
<td>
<?php echo "<a href='logs/" .$Dev_DeviceSerialNumber.".log' target='_blank'>".$Dev_DeviceSerialNumber."</a> <br>";?>
</td>
</tr>
</table>
<?php
}
}
// Free result set
mysqli_free_result($result);
mysqli_close($con);
}
?>
<?php
echo " <br>";
echo "<pre></pre>";
?>

Update specific column in loop

Is this the right way to update a specific column for one row in mysqli_array_fetch? It doesn't work for me.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {border: 1px solid black; text-align:center}
.contents { position:static}
p1 {font-size:15px; font-weight:bolder}
.inputresponse {resize:none}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row[id] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td> <p1> الإسم </p1> </td>
<tr>
<td> <?php echo $row[name] ?> </td>
</tr>
<tr>
<td> <p1> رقم التذكرة</p1> </td>
</tr>
<tr>
<td> <?php echo $row[ticketnumber] ?> </td>
</tr>
<tr>
<td> <p1> الإيميل</p1> </td>
</tr>
<tr>
<td> <?php echo $row[email] ?> </td>
</tr>
<tr>
<td> <p1> الموضوع </p1> </td>
</tr>
<tr>
<td> <?php echo $row[subject] ?> </td>
</tr>
<tr>
<td> <p1> الرد </p1> </td>
</tr>
<tr>
<td> <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td>
</tr>
<tr>
<td> <input type="submit" value="إرسال" name="send"> </td>
</tr>
<tr>
<td>
<?php
if(isset($_POST['send'])){
$repsonse = $_POST['response'];
$result = ("UPDATE contact SET response ='$response' WHERE id= $row[id]");
$rst = mysqli_query($con,$result);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
}
}
}
?>
</form>
</table>
</div>
</body>
</html>
after editing, I think I did it in wrong again
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {border: 1px solid black; text-align:center}
.contents { position:static}
p1 {font-size:15px; font-weight:bolder}
.inputresponse {resize:none}
.inputid {text-align:center; font-size:10px}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td> <input value="<?php echo $row['id'] ?>" name="id" class="inputid" readonly> </td>
<tr>
<tr>
<td> <p1> الإسم </p1> </td>
<tr>
<td> <?php echo $row['name'] ?> </td>
</tr>
<tr>
<td> <p1> رقم التذكرة</p1> </td>
</tr>
<tr>
<td> <?php echo $row['ticketnumber'] ?> </td>
</tr>
<tr>
<td> <p1> الإيميل</p1> </td>
</tr>
<tr>
<td> <?php echo $row['email'] ?> </td>
</tr>
<tr>
<td> <p1> الموضوع </p1> </td>
</tr>
<tr>
<td> <?php echo $row['subject'] ?> </td>
</tr>
<tr>
<td> <p1> الرد </p1> </td>
</tr>
<tr>
<td> <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td>
</tr>
<tr>
<td> <input type="submit" value="إرسال" name="send"> </td>
</tr>
<tr>
<td>
<?php
if(isset($_POST['send'])){
$response = $_POST['response'];
$result = ("UPDATE contact SET response ='$response' WHERE id= $row[id]");
$rst = mysqli_query($con,$result);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
}
}
}
?>
</form>
</table>
</div>
</body>
</html>
Your HTML formatting is strange but I think this should accomplish what you want.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {
border: 1px solid black;
text-align:center
}
.contents {
position:static
}
p1 {
font-size:15px;
font-weight:bolder
}
.inputresponse {
resize:none
}
.inputid {
text-align:center;
font-size:10px
}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td><input value="<?php echo $row['id'] ?>" name="id" class="inputid" type="hidden"></td>
<tr>
<tr>
<td><p1> الإسم </p1></td>
<tr>
<td><?php echo $row['name'] ?></td>
</tr>
<tr>
<td><p1> رقم التذكرة</p1></td>
</tr>
<tr>
<td><?php echo $row['ticketnumber'] ?></td>
</tr>
<tr>
<td><p1> الإيميل</p1></td>
</tr>
<tr>
<td><?php echo $row['email'] ?></td>
</tr>
<tr>
<td><p1> الموضوع </p1></td>
</tr>
<tr>
<td><?php echo $row['subject'] ?></td>
</tr>
<tr>
<td><p1> الرد </p1></td>
</tr>
<tr>
<td><textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea></td>
</tr>
<tr>
<td><input type="submit" value="إرسال" name="send"></td>
</tr>
</form>
<?php
}
?>
</table>
<?php
if(isset($_POST['send'])){
$response = $_POST['response'];
$result = "UPDATE contact SET response = ? WHERE id= ?";
$rst = mysqli_prepare($con,$result);
mysqli_stmt_bind_param($rst, 'si', $response, $_POST['id']);
mysqli_stmt_execute($rst);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
echo mysqli_stmt_error($rst);
}
}
?>
</div>
</body>
</html>
Changes/potential improvements:
Using prepared statements in place of inline values.
Moved update outside of while loop since it is irrelevant.
Moved closing form tag inside the while loop. As is you were making multiple forms but every one was a child of the first because it never closed.
The p1s look like they might be headings? If so they should be outside of the loop.
If you want to display a message next to the row that was updated you could move the whole update process before the page process. Assign it to a variable the status to a variable then in the outputting when you are on that record output the message as well.
Your table rows seem to be closing incorrectly.

:ERR_CONNECTION_CLOSED connection closed unexpectedly

I get that error in php..And I have no idea why...
Here is how my connection is established:
<?php
$hostname_QASite = "localhost";
$database_QASite = "qasite";
$username_QASite = "root";
$password_QASite = "";
$QASite = mysql_pconnect($hostname_QASite, $username_QASite, $password_QASite) or trigger_error(mysql_error(),E_USER_ERROR);
?>
my query is the following:
mysql_select_db($database_QASite, $QASite) or die(mysql_error());
$query_get_all_topics = "SELECT topic_id, title FROM topic";
$get_all_topics = mysql_query($query_get_all_topics, $QASite) or die(mysql_error());
$row_get_all_topics = mysql_fetch_assoc($get_all_topics);
$totalRows_get_all_topics = mysql_num_rows($get_all_topics);
And then I iterate over the row_get_all_topics ...
What is wrong in the code ?
Edit:
I get that error, when I try to loop 2 times over different results in the database.
UPDATE:
<body>
<br/><br/><br/><br/><br/><br/><br/>
<div align="center">
<ul id="navlist">
<li> צור נושא</li>
<li> ראה קשרים</li>
</ul>
<?php do { ?>
<table border="1">
<tr>
<td>
<table width="100%" border="1" >
<tr>
<td width="90%" align="right">
<?php echo $row_get_all_topics['title']; ?>
</td>
<td width="10%">
:שם נושא
</td>
</tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
//$result=$mysql_query("SELECT title, sub_topic_id FROM sub_topic WHERE topic_id=".$row_get_all_topics['topic_id']) or die(mysql_error());
$result="";
if($row=mysql_fetch_array($result))
{
do
{
?>
<table >
<tr>
<td>
<?php echo $row['title']; ?>
</td>
<td>
:תת נושא
</td>
</tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>
</td>
</tr>
<tr>
<td>
עדכן
</td>
<td>
מחק
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
**}while($row=mysql_fetch_assoc($result));** 1 FIRST LOOP
}//end suptopic search
?>
<?php **} while ($row_get_all_topics = mysql_fetch_assoc($get_all_topics)); ?>** 2ND LOOP
AS soon as I add this line, to query teh database inside the loop, the page shows the error..
$result=$mysql_query("SELECT title, sub_topic_id FROM sub_topic WHERE topic_id=".$row_get_all_topics['topic_id']) or die(mysql_error());

Categories