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'
// 馃憜
Related
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!
I am working on a small course registration system. I have a table called 20182019carryovertbl I select students carry over fron the table and its working well. I need to convert the selected info to an HTML form with submit button( This will go into another table 20192020coursestbl). How d i set name for my inputs
<table>
<thead>
<tr>
<th>Register course</th>
<th>Course Title</th>
<th>Corse Code</th>
<th>Unit</th>
<th>Lecturer</th>
</tr>
</thead>
<tbody>
<?php $sql = "SELECT * from 20182019carryovertbl WHERE matricno = '$matno' ";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{ ?>
<tr>
<td> <input type="checkbox" name="reg1" value="1" class="custom-control-input"></td>
<td>
<?php echo htmlentities($result->coursetitle);?>
</td>
<td>
<?php echo htmlentities($result->coursecode);?>
</td>
<td>
<?php echo htmlentities($result->unit);?>
</td>
<td>
<?php echo htmlentities($result->lecturer);?>
</td>
</tr>
<?php $cnt=$cnt+1; }} ?>
</tbody>
</table>
you can use your unique key from database like Id:
<td>
<input type="checkbox" name="reg<?php echo $result->id;" value="1"class="custom-control-input">
</td>
and it's gonna be unique name
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>";
?>
I am facing a unknown problem while I go insert data.Some data getting inserted in same table n same column but except one.
The following is my code.
<html>
<body>
<?php
include("index.php");
?>
<form action="addcenter.php" method="post">
<table align="center" border="9" width="600">
<tr>
<td align="center" colspan="5" bgcolor="yellow">
<h1>Add Your Center Details</h1></td>
</tr>
<tr>
<th>District Name</th>
<td><input type="text" name="district"></td>
</tr>
<tr>
<th>Phone No.</th>
<td><input type="text" name="phone"></td>
</tr>
<tr>
<th>Person's Name</th>
<td><input type="text" name="person"></td>
</tr>
<tr>
<th>Designation</th>
<td><input type="text" name="designation"></td>
</tr>
<tr>
<td align="center" colspan="5"><input type="submit" name="submit"
value="submit"></td>
</tr>
</table>
</form>
<?php
include("includes/connect.php");
if(isset($_POST['submit']))
{
$district=$_POST['district'];
$phone=$_POST['phone'];
$person=$_POST['person'];
$designation=$_POST['designation'];
if($district=='' or $phone=='' or $person=='' or $designation='')
{
echo"<script> alert('Please fill the fiels')</script> ";
exit();
}
$query="insert into centers (District,Phone,ContactPerson,Designation)
values('$district','$phone','$person','$designation') ";
if(mysql_query($query))
{
echo"<center><h1>Details Successfully added to your database</h1>
</center> ";
}
}
?>
<table width=" 900" align="center" border="3">
<tr>
<td align="center" colspan="9" bgcolor="orange"><h1>View all
Centers</h1></td>
</tr>
<tr align="center">
<th>SL No.</th>
<th>District</th>
<th>Phone No</th>
<th>Contact Person</th>
<th>Designation</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php
$query="select * from centers";
$run=mysql_query($query);
$i=1;
while($row=(mysql_fetch_array($run)))
{
$center_id=$row['center_id'];
$district=$row['District'];
$phone=$row['Phone'];
$contact_person=$row['ContactPerson'];
$designation=$row['Designation'];
?>
<tr align="center">
<td><?php echo $i++ ;?></td>
<td><?php echo $district;?></td>
<td><?php echo $phone ;?></td>
<td><?php echo $contact_person ;?></td>
<td><?php echo $designation ;?></td>
<td>Edit
</td>
<td><input type="button" onclick="deleteme1(<?php echo $center_id ?>)"
name="delete" value="Delete"></td>
</tr>
<script language="javascript">
function deleteme1(delid1)
{
if(confirm("are u sure"))
{
window.location.href='deletecenter.php?del_id1='+delid1+'';
return true;
}
}
</script>
<?php } ?>
</table>
</body>
</html>
The problem is that when I going to insert the Contactperson,district,designation and phone no.Then only the data of Contactperson,district and phone no get inserted but not the designation..I dont know why this is happening even the coding is also right..Please help me. Thankyou
Your "if" statement is assigning '' to $designation. Use '==' for comparison.
if($district=='' or $phone=='' or $person=='' or $designation**=**'')
The if statement says, "if $district is '' or $phone is '' or $person is '' or 'I can assign nothing to $designation (which always succeeds)' - at which point you have successfully assigned '' to $designation. The if statement finishes and you insert '' into designation.
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());