database not updating after attempting to edit with update statement - php

My question to you is as follows. I have created a form that is populated from a mysql database. Id like to be able to edit that form after it has been submitted. I have got it to the point where it will allow me to edit the fields in the form but when i do so the data is not updated on the database. Could you have a look at my code and see where i might be going wrong?
<?php
include_once 'includes/db_connect.php';
?>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa7">Acceptance Criteria</td>
<td class="headingsa8">Technician Responsible</td>
</tr>
<tr>
<td class="headings1">Job/Order Number:</td>
<td class="answers1"><div class= "typesection1">
<?php echo ($row['job_order_number'] ); ?></div></td>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php
echo ($row['acceptance_criteria1'] );
?>
</div>
</td>
<td class="answersa8">
<div class= "typesectiona8">
<?php
echo($row['technician_responsible1'] );
?>
</div></td>
</tr>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?
php echo ($row['acceptance_criteria2'] );
?>
</div></td>
<td class="answersa8">
<div class= "typesectiona8">
<?php
echo ($row['technician_responsible2'] );
?>
</div>
</td>
</tr>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php
echo ($row['acceptance_criteria3'] );
?>
</div>
</td>
<td class="answersa8">
<div class= "typesectiona8">
<?php
echo ($row['technician_responsible3'] );
?>
</div>
</td>
</tr>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php
echo($row['acceptance_criteria4'] );
?>
</div>
</td>
<td class="answersa8">
<div class= "typesectiona8">
<?php
echo($row['technician_responsible4'] );
?>
</div>
</td>
</tr>
</table>
<br /><br />
<center>
<?php echo "Edit | Delete |
?>
</center>
</div>
</body>
</html>
edit page.php
</head>
<body>
<?php
mysql_connect("localhost","username","password");
mysql_select_db("joziweb1_form");
$order = "SELECT * FROM jobrequest";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa7">Acceptance Criteria</td>
<td class="headingsa8">Technician Responsible</td>
</tr>
<tr>
<td class="headings1">Job/Order Number:</td>
<td class="answers1">
<div class= "typesection1">
<?php
echo $_GET['job_order_number'];
?>
</div>
</td>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php
echo ($row['acceptance_criteria1'] );
?>
</div>
</td>
<td class="answersa8"><input class="typesectiona8" type="text" name="Technician_responsible1"value=<?php echo $technician_responsible1;?>>
</td>
</tr>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php echo ($row['acceptance_criteria2'] ); ?>
</div>
</td>
<td class="answersa8">
>
<td class="answersa8">
>
>
Edit_data.php
<?php
mysql_connect("localhost","username","password");
mysql_select_db("databasename");
$order = "UPDATE jobrequest,
SET technician_responsible1='$Technician_responsible1', technician_responsible2='$Technician_responsible2' technician_responsible3='$Technician_responsible3', technician_responsible4='$Technician_responsible4',
WHERE 'technician_responsible1' , 'technician_responsible2' , 'technician_responsible3' , 'technician_responsible4' , “;
mysql_query($order);
header("location:jobrequest_viewform.php");
?>

in a edit.php page add this code
session_start();
$_SESSION['no']=$_GET['job_order_number'];
in a edit_data.php
session_start();
$no=$_SESSION['no'];
then use
$order = "UPDATE jobrequest,
SET technician_responsible1='$Technician_responsible1',technician_responsible2='$Technician_responsible2',technician_responsible3='$Technician_responsible3',technician_responsible4='$Technician_responsible4',
WHERE job_order_number='$no'“;
mysql_query($order);
try this maybe it work..

Related

when i do form the popup window displays in just a second then hide again

I have popup it works normal i need to use method post to get my value from the input balise but the problem is when i do form the popup window displays in just a second then hide again and I need to click two time becausethe first time i got just the last result
<div class="List_modify">
<table class="list">
<thead class="topBar">
<tr>
<th>Prenom</th>
<th>Nom</th>
<th>CIN</th>
<th>Emails</th>
<th>Références</th>
<th>Photos</th>
<th>Niveau</th>
<th class="button_editer" style="vertical-align:middle"><span>Editer</span></th>
</tr>
</thead>
<?php $requet = "select * from Etudiants";
$resultat = mysqli_query($connecte, $requet);
while ($r = mysqli_fetch_array($resultat)) {
?>
<tbody class="container">
<tr>
<td>
<?php echo $r['Prenom']; ?>
</td>
<td>
<?php echo $r['Nom']; ?>
</td>
<td>
<?php echo $r['CIN']; ?>
</td>
<td>
<?php echo $r['Emails']; ?>
</td>
<td>
<?php echo $r['Matricule']; ?>
</td>
<td> <img src="image/<?php echo $r['Photo']; ?> " style="width: 150px; height:150px;"></td>
<td>
<?php echo $r['Niveau']; ?> </td>
<td>
<form method="POST" action="">
<input type="hidden" name="id" value="<?php echo $r['Id_Etudiant']; ?>">
<button class=" button" onclick="show()" style="vertical-align:middle" type="submit" name="submit"><span>Editer<i class=" fas fa-user-edit"></i></span>
</button>
</form>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
<div class="background_page_modify" id="page_modify" onclick="hide()">
<div class="page_etudiant" onclick="event.stopPropagation()">
<div class="closebtn" id="closebtn" onclick="hide()">
<div class="circle"> +</div>
</div>
<div class="etudiant_box">
<?php
if (isset($_REQUEST['submit'])) {
$checkid = $_REQUEST['id'];
echo $checkid;
}
?>
</div>
</div>
</div>

For loop is going again and again for the same values

I am not sure what is going wrong. But the system is printing the same values again and again, where it should echo the value only once where it is matching student_id in the delivery table. The full code I have edited as requested. This is not executing the query but able display the Table headings.
The code is :
<?php $min = $this->db->get_where('academic_settings' , array('type' =>'minium_mark'))->row()->description;?>
<?php $running_year = $this->db->get_where('settings' , array('type' => 'running_year'))->row()->description; ?>
<div class="content-w">
<div class="conty">
<?php include 'fancy.php';?>
<div class="header-spacer"></div>
<div class="content-i">
<div class="content-box">
<div class="row">
<div class="table-responsive">
<table width="100%" class="table table-striped table-lightfont">
<tbody>
<tr>
<td style="color:black !important; text-transform:uppercase; text-align:center;">
<?php echo get_phrase('Subject_Name');?> :
<span><?php echo $row['name'];?></span>
</td>
</tr>
<tr>
<td>
<table class="table table-padded">
<thead style="background-color:#90be2e; color:white;">
<tr style="padding-bottom:4px; padding-top:4px;">
<th style="color:white;"><?php echo get_phrase('Publish Date');?></th>
<th style="color:white;"><?php echo get_phrase('Assignment');?></th>
<th style="color:white;"><?php echo get_phrase('Faculty');?></th>
<th style="color:white;"><?php echo get_phrase('Last Date');?></th>
<th style="color:white;"><?php echo get_phrase('Submitted On');?></th>
<th style="color:white;"><?php echo get_phrase('Marks');?></th>
<th style="color:white;"><?php echo get_phrase('Feedback');?></th>
</tr>
</thead>
<tbody>
<?php
$uploader_id_student = $this->db->get_where('student', array('student_id' => $this->session->userdata('login_user_id')))->row()->student_id;
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
foreach($invoices as $row2):
?>
<tr>
<td>
<?php echo $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row()->upload_date;?>
</td>
<td>
<?php
$get_homework_data = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row();
echo wordwrap($get_homework_data->title,15,"<br>\n");
?>
</td>
<td>
<?php
echo $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row()->first_name;
?>
<?php
echo $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row()->last_name;
?>
</td>
<td>
<?php
$sampleDate1 = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row()->date_end;
$convertDate1 = date("d-m-Y", strtotime($sampleDate1));
echo $convertDate1;
?>
</td>
<td>
<?php
$sampleDate = $row2['date'];
$convertDate = date("d-m-Y", strtotime($sampleDate));
echo $convertDate;
?>
</td>
<td style="text-align:center;">
<?php echo $row2['mark'];?>
</td>
<td>
<?php echo wordwrap($row2['teacher_comment'],25,"<br>\n");?>
</td>
</tr>
<?php endforeach;?>
<!--<?php endforeach;?> -->
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
attached is screenshot of table Deliveries is there Deliveries Picture Download
Here is your code updated to fix the performance issues mentioned by Arnold Daniels.
<?php
$uploader_id_student = $this->session->userdata('login_user_id');
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
foreach($invoices as $row2) {
$get_homework_data = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row();
$teacher = $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row();
?>
<tr>
<td>
<?= $get_homework_data->upload_date ?>
</td>
<td>
<?= wordwrap($get_homework_data->title,25,"<br>\n") ?>
</td>
<td>
<?= $teacher->first_name . ' ' . $teacher->last_name ?>
</td>
</tr>
<?php
}
?>
It appears to be working fine as far as I could test it. Is there anything missing from the snippet you posted that could help reproduce your issue?
Edit:
So the complete code would be:
<?php
$min = $this->db->get_where('academic_settings' , array('type' =>'minium_mark'))->row()->description;
$running_year = $this->db->get_where('settings', array('type' => 'running_year'))->row()->description;
?>
<div class="content-w">
<div class="conty">
<?php include 'fancy.php'; ?>
<div class="header-spacer"></div>
<div class="content-i">
<div class="content-box">
<div class="row">
<div class="table-responsive">
<table width="100%" class="table table-striped table-lightfont">
<tbody>
<tr>
<td style="color:black !important; text-transform:uppercase; text-align:center;">
<?php echo get_phrase('Subject_Name'); ?> :
<span><?php echo $row['name']; ?></span>
</td>
</tr>
<tr>
<td>
<table class="table table-padded">
<thead style="background-color:#90be2e; color:white;">
<tr style="padding-bottom:4px; padding-top:4px;">
<th style="color:white;"><?php echo get_phrase('Publish Date'); ?></th>
<th style="color:white;"><?php echo get_phrase('Assignment'); ?></th>
<th style="color:white;"><?php echo get_phrase('Faculty'); ?></th>
<th style="color:white;"><?php echo get_phrase('Last Date'); ?></th>
<th style="color:white;"><?php echo get_phrase('Submitted On'); ?></th>
<th style="color:white;"><?php echo get_phrase('Marks'); ?></th>
<th style="color:white;"><?php echo get_phrase('Feedback'); ?></th>
</tr>
</thead>
<tbody>
<?php
$uploader_id_student = $this->db->get_where('student', array('student_id' => $this->session->userdata('login_user_id')))->row()->student_id;
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
foreach ($invoices as $row2) :
$homework_data = $this->db->get_where('homework', array('homework_code' => $row2['homework_code']))->row();
$teacher = $this->db->get_where('teacher', array('teacher_id' => $get_homework_data->uploader_id))->row();
?>
<tr>
<td>
<?php echo $homework_data->title->upload_date; ?>
</td>
<td>
<?php
echo wordwrap($homework_data->title, 15, "<br>\n");
?>
</td>
<td>
<?php
echo $teacher->first_name;
?>
<?php
echo $teacher->last_name;
?>
</td>
<td>
<?php
$sampleDate1 = $homework_data->date_end;
$convertDate1 = date("d-m-Y", strtotime($sampleDate1));
echo $convertDate1;
?>
</td>
<td>
<?php
$sampleDate = $row2['date'];
$convertDate = date("d-m-Y", strtotime($sampleDate));
echo $convertDate;
?>
</td>
<td style="text-align:center;">
<?php echo $row2['mark']; ?>
</td>
<td>
<?php echo wordwrap($row2['teacher_comment'], 25, "<br>\n"); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
I would need to see the contents of the included file "fancy.php" to be sure. There was an extra endforeach statement, but I'm guessing that it came from somewhere beyond the scope of the snippet you updated. I would need to see the whole content of the file and the content of the included script in order to determine the true nature of the error.
<!--<?php endforeach;?> -->
Remove this Line

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.

Php calculation is posting as 0

I am having a problem with getting the calculation to post anything but 0. all other post has the correct info from the form but the calculation is not working. all the data that comes from the inputs and the calculation of the total pallets works. It is just the total price.
The whole form:
if(!checkAdmin()) {
header("Location: login.php");
exit();
}
$page_limit = 10;
// filter GET values
foreach($_GET as $key => $value) {
$get[$key] = filter($value);
}
foreach($_POST as $key => $value) {
$post[$key] = filter($value);
}
$rs_all = mysql_query("select count(*) as total_all from users") or die(mysql_error());
list($all) = mysql_fetch_row($rs_all);
?>
<?php
$rs_pickup = mysql_query("select count(*) as total_all from pickups") or die(mysql_error());
list($pickup) = mysql_fetch_row($rs_pickup);
?>
<?php
$sql="SELECT companyid, company FROM company ";
$result=mysql_query($sql) or die(mysql_error());
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["companyid"];
$thing=$row["company"];
$options.="<OPTION VALUE=\"$id\">".$thing.'</option>';
}
?>
<?php
?>
<?php
$err = array();
if($_POST['doPickup'] == 'Enter Pickup')
if(empty($err)) {
$companyid = $_POST['companyid'];
$sql_grd = "SELECT companyid, grade_a_pu, grade_b_pu, grade_c_pu, ns_pu, custom_pu FROM company WHERE companyid = $companyid";
$result_grd=mysql_query($sql_grd) or die(mysql_error());
while ($row_grd=mysql_fetch_array($result_grd))
{
$price_a = $row_grd["grade_a_pu"];
$price_b = $row_grd["grade_b_pu"];
$price_c = $row_grd["grade_c_pu"];
$price_ns = $row_grd["ns_pu"];
$price_cus = $row_grd["custom_pu"];
}
$total_credit = (($_POST['grade_a_pal']*$price_a)+($_POST['grade_b_pal']*$price_b)+($_POST['grade_c_pal']*$price_c)+($_POST['ns_pal']*$price_ns)+($_POST['cus_pal']*$price_cus));
$sql_insert = "INSERT into `pickups`
(`companyid`,`pu_date`,`trail_num`,`grade_a_pal`,`grade_b_pal`,`grade_c_pal`,`ns_pal`,`cus_pal`,`pal_pu`,`credit`)
VALUES ('$_POST[companyid]','$_POST[pu_date]','$_POST[trail_num]','$_POST[grade_a_pal]','$_POST[grade_b_pal]','$_POST[grade_c_pal]','$_POST[ns_pal]','$_POST[cus_pal]','$_POST[pal_pu]','$total_credit')";
mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
}
?>
<html>
<head>
<title>USMI Pallets, Inc. :: Pickup Entry Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="styles.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$("#datepicker").datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true
});
});
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php include("header.php"); ?>
<tr>
<td colspan="3" height="23" valign="top" style="background-color:#A42914 ">
</td>
</tr>
<?php include("admin_menu.php"); ?>
<td width="800" valign="top" style="padding: 10px;">
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="myaccount">
<tr>
<td>Total Pickups: <?php echo $pickup;?></td>
</tr>
</table>
<p><?php
if(!empty($msg)) {
echo $msg[0];
}
?></p>
<table width="80%" border="0" align="center" cellpadding="10" cellspacing="0" style="background-color: #E4F8FA;padding: 2px 5px;border: 1px solid #CAE4FF;" >
<tr>
<td><form name="form1" method="get" action="pickup_ent.php">
<p align="center">Search Account:
<SELECT NAME=companyid id="q">
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>
<br>
</p>
<p align="center">
<input name="doSearch" type="submit" id="doSearch2" value="Search">
</p>
</form></td>
</tr>
</table>
<p>
<?php if ($get['doSearch'] == 'Search') {
$sql = "SELECT * FROM pickups WHERE companyid = '$_REQUEST[companyid]' ORDER BY pu_date DESC";
$rs_total = mysql_query($sql) or die(mysql_error());
$total = mysql_num_rows($rs_total);
if (!isset($_GET['page']) )
{ $start=0; } else
{ $start = ($_GET['page'] - 1) * $page_limit; }
$rs_results = mysql_query($sql . " limit $start,$page_limit") or die(mysql_error());
$total_pages = ceil($total/$page_limit);
?>
<?php
// outputting the pages
if ($total > $page_limit)
{
echo "<div><strong>Pages:</strong> ";
$i = 0;
while ($i < $page_limit)
{
$page_no = $i+1;
$qstr = ereg_replace("&page=[0-9]+","",$_SERVER['QUERY_STRING']);
echo "$page_no ";
$i++;
}
echo "</div>";
} ?>
<form name "searchform" action="pickup_ent.php" method="post">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
<tr bgcolor="#E6F3F9">
<td class="myheader">ID</td>
<td class="myheader">Company #</td>
<td class="myheader">Date</td>
<td class="myheader">Trailer Number</td>
<td class="myheader">Grade A</td>
<td class="myheader">Grade B</td>
<td class="myheader">Grade C</td>
<td class="myheader">Non-Std</td>
<td class="myheader">Custom</td>
<td class="myheader">Total Pickup</td>
<td class="myheader">Total Credit</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php while ($rrows = mysql_fetch_array($rs_results)) {?>
<tr>
<td> <div align="center"><?php echo $rrows['pickup_id']; ?></div> </td>
<td> <div align="center"><?php echo $rrows['companyid']; ?></div></td>
<td> <div align="center"><?php echo $rrows['pu_date']; ?></div></td>
<td> <div align="center"><?php echo $rrows['trail_num'];?></div></td>
<td> <div align="center"><?php echo $rrows['grade_a_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['grade_b_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['grade_c_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['ns_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['cus_pal'];?></div></td>
<td> <div align="center"><?php echo $rrows['pal_pu'];?></div></td>
<td> <div align="center">$<?php echo $rrows['credit'];?></div></td>
<td width="10%">Edit Delete</td>
</tr>
<tr>
<?php } ?>
</table>
<p><br>
</form>
<?php } ?>
</p>
<h2><font color="#FF0000">Pickup Entry
Page</font></h2>
<p> </p>
<form name "pickupform" action="pickup_ent.php" method="post">
<table width="80%" border="0" align="center" cellpadding="10" cellspacing="0" style="background-color: #E4F8FA;padding: 2px 5px;border: 1px solid #CAE4FF;" >
<tr>
<td>
Account:
<SELECT NAME=companyid>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT> </td>
</tr>
<tr>
<td>Date: <input name="pu_date" type="text" id="datepicker" /></td>
</tr>
<tr>
<td>Trailer #:<select name="trail_num" id="trail_num">
<option selected value=""></option>
<option value="1986-1">1986-1</option>
<option value="1986-2">1986-2</option>
<option value="1986-3">1986-3</option>
<option value="1986-4">1986-4</option>
<option value="1986-5">1986-5</option>
<option value="1986-6">1986-6</option>
<option value="1986-7">1986-7</option>
<option value="1986-8">1986-8</option>
<option value="1986-9">1986-9</option>
<option value="1986-10">1986-10</option>
<option value="1986-11">1986-10</option>
<option value="1986-12">1986-12</option>
</select></td>
</tr>
<tr>
<td>Grade A Pallets: <input id="grade_a_pal" name="grade_a_pal" type="text" size="8"> </td>
</tr>
<tr>
<td>Grade B Pallets: <input id="grade_b_pal" name="grade_b_pal" type="text" size="8"> </td>
</tr>
<tr>
<td>Grade C Pallets: <input id="grade_c_pal" name="grade_c_pal" type="text" size="8"> </td>
</tr>
<tr>
<td>Non-Standard Pallets: <input id="ns_pal" name="ns_pal" type="text" size="8"></td>
</tr>
<tr>
<td>Custom Pallets: <input id="cus_pal" name="cus_pal" type="text" size="8"></td>
</tr>
<tr>
<tr>
<td>Total Pallets Picked Up:
<input id="pal_pu" name="pal_pu" type="text" size="8" readonly></td>
</tr>
<td><input name="doPickup" type="submit" id="doPickup" value="Enter Pickup"></p>
</td>
</tr>
</table>
<script>
$(document).ready(function() {
//this calculates values automatically
sum();
$("#grade_a_pal, #grade_b_pal, #grade_c_pal, #cus_pal").on("keydown keyup", function() {
sum();
});
});
function sum() {
var grade_a_pal = document.getElementById('grade_a_pal').value;
var grade_b_pal = document.getElementById('grade_b_pal').value;
var grade_c_pal = document.getElementById('grade_c_pal').value;
var ns_pal = document.getElementById('ns_pal').value;
var cus_pal = document.getElementById('cus_pal').value;
var result = parseInt(grade_a_pal) + parseInt(grade_b_pal) + parseInt(grade_c_pal) + parseInt(ns_pal) + parseInt(cus_pal);
if (!isNaN(result)) {
document.getElementById('pal_pu').value = result;
}
}
</script>
</form>
<p> </p>
<p> </p>
<p> </p></td>
<td width="12%"> </td>
</tr>
<tr>
<td colspan="3" height="43" valign="top" style="background-color:#A42914 ">
<table width="766" style="height:100% " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" class="myfooter">
<div style="margin:12px 0px 0px 31px; ">
© 2012 USMI Pallets, Inc. All rights reserved
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
It appears you are using $_post (lower case) instead of $_POST (uppercase) for your pallets vars.
Try outputting a print_r($_POST) to see what you are getting in your $_POST array. It could just be you are referencing the wrong vars.

Avoiding PDF creation on entering the page in PHP with mpdf

I've been struggling these past days to export a table to PDF in PHP with mpdf, I finally solved most of the problems, however, I'm only able to create the pdf and store it in the server files automaticlly when opening the page, instead I would like to have the pdf only created after pressing a button. Here is my code:
<?php if ( have_posts() ) : while (have_posts() ) : the_post(); ?>
<h3><?php the_title() ?></h3>
<?php ob_start(); ?>
<div id="customers">
<table border='1'>
<thead>
<tr>
<td>
<h1 class="table2" >Periodo de Inversión</h1>
</td>
<td>
<h1 class="table2" >Saldo Inicial</h1>
</td>
<td>
<h1 class="table2" >Inversión en el Periodo</h1>
</td>
<td>
<h1 class="table2" >Interés Causado en el Periodo</h1>
</td>
<td>
<h1 class="table2" >Intereses Pagados</h1>
</td>
<td>
<h1 class="table2" >Intereses Reinvertidos</h1>
</td>
<td>
<h1 class="table2" >Saldo</h1>
</td>
</tr>
</thead>
<tbody>
<?php
if( have_rows('datos_especificos') ):
?>
<?php
while ( have_rows('datos_especificos') ) : the_row();
$icelpx = get_sub_field('interes_causado_en_el_periodo');
$cpx = get_sub_field('cantidad_pagada');
$crx = $icelpx-$cpx;
$sal1x = get_sub_field('saldo');
$ipx = get_sub_field('inversion_en_el_periodo');
$sal2x = $sal1x+$ipx+$crx;
$fech = get_sub_field('fecha');
$sal1 = get_sub_field('saldo');
$ielp = get_sub_field('inversion_en_el_periodo');
$icelp = get_sub_field('interes_causado_en_el_periodo');
$cp = get_sub_field('cantidad_pagada');
$cr = $icelp-$cp;
$crt = $crt+$cr;
$sal2 = $sal1+$ip+$cr;
$igalf = $igalf+$icelp;
$fech2 = $fech+100;
$ID= $the_query->ID;
?>
<tr>
<td>
<p class="table"> <?php the_sub_field('fecha') ?> </p>
</td>
<td>
<p class="table"> <?php the_sub_field('saldo') ?> </p>
</td>
<td>
<p class="table"> <?php the_sub_field('inversion_en_el_periodo') ?> </p>
</td>
<td>
<p class="table"> <?php the_sub_field('interes_causado_en_el_periodo'); ?> </p>
</td>
<td>
<p class="table"> <?php the_sub_field('cantidad_pagada'); ?> </p>
</td>
<td>
<p class="table"> <?php echo $crx; ?> </p>
</td>
<td>
<p class="table"> <?php echo $sal2x; ?> </p>
</td>
</tr>
<?php
endwhile;
else :
// no rows found
endif;
?>
</tbody>
</table>
</div>
<br>
<table>
<tr>
<td>
<p class="table"> Saldo Inicial <?php echo $fech; ?> </p>
</td>
<td>
<p class="table"> <?php echo $sal1; ?> </p>
</td>
</tr>
<td>
<p class="table"> Nuevas Inversiones </p>
</td>
<td>
<p class="table"> <?php echo $ielp; ?> </p>
</td>
<tr>
<td>
<p class="table"> Intereses Pagados </p>
</td>
<td>
<p class="table"> <?php echo $cp; ?> </p>
</td>
</tr>
<tr>
<td>
<p class="table"> Intereses Reinvertidos </p>
</td>
<td>
<p class="table"> <?php echo $crt; ?> </p>
</td>
</tr>
<tr>
<td>
<p class="table"> Total Intereses Generados a la fecha</p>
</td>
<td>
<p class="table"> <?php echo $igalf; ?> </p>
</td>
</tr>
<tr>
<td>
<p class="table"> Saldo Inicial <?php echo $fech2; ?> </p>
</td>
<td>
<p class="table"> <?php echo $sal2; ?> </p>
</td>
</tr>
</table>
<?php $tableVar = ob_get_contents();
$mpdf=new mPDF();
$stylesheet = file_get_contents(get_template_directory_uri() . 'style.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($tableVar,2);
$mpdf->Output('test8.pdf','F');
?>
Generate pdf //THIS BUTTON DOES NOTHING FOR NOW.
<hr>
<?php endwhile; else: ?>
<p>There are no posts or pages here</p>
<?php endif; ?>
To further explain my comment (and this isn't necessarily the best way to do this) you could change the link from this:
Generate pdf
To a form like this:
<form method="post"><input type="submit" value="Generate pdf"/></form>
And then wrap your PDF stuff in something like this:
if( 'POST' === $_SERVER['REQUEST_METHOD'] )
{
$mpdf=new mPDF();
$stylesheet = file_get_contents(get_template_directory_uri() . 'style.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($tableVar,2);
$mpdf->Output('test8.pdf','F');
}
There's some security things and edge cases you might want to consider but this is a good basic start

Categories