Grab multidimensional array value in to table using foreach loop - php

This is my code; I will tell you the issue then.
<?php
//checking for perfect loging
session_start();
$user_name = $_SESSION['username'];
$user_pass = $_SESSION['password'];
require ("connection.php");
if ( $user_name == '' ) {
header('location:home.php');
exit();
}
/////////////////////////////////////
?>
<?php
//collecting posted variables by pressing addanother button
if(isset($_POST['adnother'])) {
$date = $_POST['date'];
$billnmbr = $_POST['billnmbr'];
$itemcode = $_POST['itemcode'];
$itemname = $_POST['itemname'];
$exdate = $_POST['exdate'];
$eachprice = $_POST['eachprice'];
$itmtotal = $_POST['itmtotal'];
$wasFound=false;
$i=0;
// check for >>>>>>>>>>> if the session bill_array array is not set or cart array is empty <<<<<<<<<<<<<<<
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
// Run if the bill_array is empty or not set
$_SESSION["bill_array"]= array(1 => array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
} else {
// Run if the bill has at least one item in it
foreach($_SESSION["bill_array"] as $each_item) {
$i++;
while(list($key,$value)=each($each_item)){
if($key=="itemcode" && $value == $itemcode){
// That item is in cart already so push a error message in to screen
$wasFound = true;
?>
<script type="text/javascript">
var error = "<?= $wasFound ?>";
if(error == "true") {
alert("You trying to add same item twice")
}
</script>
<?php
}//close if condition
}//close while loop
}//close foreach loop
//if the next item is not in the bill and then add it to the bill_array
if($wasFound==false){
array_push($_SESSION["bill_array"],array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
}//clos if condition
}//close else statment
}//close ifisset
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Front-end Billing</title>
<link href="main.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
.mainheder {
font-size: 36px;
font-weight: bolder;
color: #00C;
text-align: center;
}
#headertopic {
position:absolute;
left:304px;
top:1px;
width:395px;
height:44px;
z-index:1;
background-color: #999900;
}
#mainmenue {
position:absolute;
left:208px;
top:78px;
width:614px;
height:48px;
z-index:10000;
}
#dateandtime {
position:absolute;
left:790px;
top:251px;
width:208px;
height:82px;
z-index:1;
}
#redcross {
position:absolute;
left:377px;
top:321px;
width:247px;
height:239px;
z-index:0;
}
#usrlogin {
position:absolute;
left:4px;
top:216px;
width:265px;
height:184px;
z-index:1;
}
#address {
position:absolute;
left:2px;
top:462px;
width:204px;
height:155px;
z-index:2;
}
#logdas {
position:absolute;
left:10px;
top:92px;
width:197px;
height:58px;
z-index:1;
}
.logdas {
font-weight: bold;
color: #00F;
}
#pagetheam {
position:absolute;
left:332px;
top:49px;
width:341px;
height:24px;
z-index:1;
text-align: center;
font-size: 18px;
font-weight: bolder;
color: #0CF;
text-decoration: underline;
}
#billingitems {
position:absolute;
left:11px;
top:186px;
width:489px;
height:293px;
z-index:1;
}
#printlayout {
position:absolute;
left:531px;
top:186px;
width:211px;
height:322px;
z-index:1;
text-align: center;
}
.printlayoutshopname {
font-size: 14px;
font-weight: bold;
color: #000;
}
.billaddrs {
font-size: 10px;
}
.bilnmbr {
font-size: 10px;
font-weight: bold;
text-align: left;
}
</style></head>
<body>
<div id="wrap">
<div id="headertopic" class="mainheder">Accoutnig for Phamacy</div>
<p> </p>
<p> </p>
<div id="mainmenue"> <?php // include 'index.html' ;?> </div>
<div id="logdas"><p class="logdas">Logged in as : <?php echo $user_name; ?></p>
<p class="logdas">Date : <?php echo date("Y-m-d") ?></p>
</div>
<div id="pagetheam">Front-end Billing </div>
<div id="billingitems">
<form id="form1" name="form1" method="post" action="biling.php">
<?php $data = mysql_query("SELECT * FROM billnumber ") ;
$info = mysql_fetch_array( $data );
$oldnumber = $info['bill_number'];
$oldnumber= $oldnumber + 1;
$Transaction_number = "PM". $oldnumber ;
?>
<table width="490" height="282" border="0">
<tr>
<td width="160"><input type="hidden" name="date" id="date" value=" <?php echo date("Y-m-d") ?> " /><?php echo date("Y-m-d") ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td width="206">Bill Number</td>
<td width="160"><input type="hidden" name="billnmbr" id="billnmbr" value="<?php echo $Transaction_number; ?>" /><?php echo $Transaction_number; ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td>Item Code</td>
<td><input type="text" name="itemcode" id="itemcode" tabindex="1" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Name</td>
<td><input type="text" name="itemname" id="itemname" tabindex="2" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Expier Date</td>
<td><input type="text" name="exdate" id="exdate" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Price</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Each :
<input type="text" name="eachprice" id="eachprice" /></td>
<td>Total :
<input type="text" name="itmtotal" id="itmtotal" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="adnother" id="adnother" value="add another item" tabindex="5" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
</div>
<div id="printlayout">
<p><span class="printlayoutshopname">Yasitha Pharacy<br />
</span><span class="billaddrs">22,Colombathanthiri Mawatha, Ethulkotte, Kotte.</span></p>
<table width="211" border="0">
<tr>
<td width="103"><span class="bilnmbr">Bill No: <?php echo $Transaction_number; ?></span></td>
<td colspan="2" class="bilnmbr">Date: <?php echo date("Y-m-d") ?></td>
</tr>
<?php
if(isset($_POST['adnother'])) {
//taking items in the bill to variables if the bill_array is not empty.
$cartOutput="";
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
$cartOutput = "<h2 align='center'> Bill is still empty </hd>";
}
else {
$i = 0;
foreach ($_SESSION["bill_array"]as $each_item ): ?>
<tr>
<td class="bilnmbr">Item code: </td>
<td colspan="2" class="bilnmbr"><?php echo $each_item['itemcode']; ?></td>
</tr>
<tr>
<td colspan="3" class="bilnmbr">Item Name:</td>
</tr>
<tr>
<td colspan="3" class="bilnmbr"><?php echo $each_item['itemname']; ?></td>
</tr>
<tr class="bilnmbr">
<td>Each</td>
<td width="98">Qty</td>
<td width="98">Total</td>
</tr>
<tr class="bilnmbr">
<td><?php echo $each_item['eachprice']; ?></td>
<td>20</td>
<td><?php echo $each_item['itmtotal']; ?></td>
</tr>
</table>
<?php endforeach; ?>
<?php
}
}
////////////////////////////////////////
?>
<p>
</p>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php //closing div for wrapper?>
</div>
</body>
</html>
I used two dimensional array for insert item details to a session array, after inserting a item I want its details to be displayed in a separate table (right hand side) there is no problem with one item, when I add a item it is viewing in the perfect place, but when I add the second item it is going under that table without creating new row. What is the wrong with what I had done?

I found my error
i ended my foreach loop like this
</tr>
</table>
<?php endforeach;
}
}
////////////////////////////////////////
?>
but now i corrected to this way
</tr>
<?php endforeach;
}
}
////////////////////////////////////////
?>
</table>
now it's all ok.... thank you guys for wasting your time for my silly mistake... sorry.... :(

Related

How can I get the value of it from html to php?

How can I get the value of information from html to php? with the calculation of Interest = Loan Amount * 5% (or 10%), Total Loan Amount = Loan Amount + Interest, Monthly Dues = Total Loan Amount / Number of Terms (6, 12, 24). What should write in php?
<!doctype html>
<html lang= "en">
<head><title>Registration Form</title>
<style>
.Cn{
text-align:center;
color:#1e90ff;
font-family:Arial, Helvetica, sans-serif;
}
.add{
color:black;
font-family:Arial, Helvetica, sans-serif;
}
.h1{
text-align:center;
color:black;
font-family:Arial, Helvetica, sans-serif;
}
table, th, td {
border: 1px solid black;
align:center;
}
table.center{
margin-left:auto;
margin-right:auto;
}
table {
border-collapse: collapse;
}
</style>
</head>
<body>
<form action="LoanInformation.php" method="post">
<h2 class="Cn">Loan</h2>
<center class="add">blah City<br>
Mobile Number: 12345678900 <br> Telephone:(08)9999999
</center>
<hr style="Width:100%;color:#dc143c">
Borrower Information:<br>
Name:<input type"text" name="name"><br>
Address:<input type"text" name="address"><br>
Contact#:<input type"text" name="contact">
<h1 class="h1">Loan Amount</h1>
<div>
<table class="center">
<tr>
<th>Select Loan Amount</th>
</tr>
<tr>
<td><input type="radio" name='r1' value="Php 5,000">Php 5,000</td>
</tr>
<tr>
<td><input type="radio" name='r1' value="Php 10,000">Php 10,000</td>
</tr>
<tr>
<td><input type="radio" name='r1' value="Php 15,000">Php 15,000</td>
</tr>
<tr>
<td><input type="radio" name='r1' value="Php 20,000">Php 20,000</td>
</tr>
<td><input type="radio" name='r1' value="Php 25,000">Php 25,000</td>
</tr>
<tr>
<th>Terms of Payment</th>
</tr>
<tr><td><input type="radio" name="r2" value="6 months">6 mos</td></tr>
<tr><td><input type="radio" name="r2" value="12 months">12 mos</td></tr>
<td><input type="radio" name="r2" value="24 months">24 mos</td>
<tr> <th>Cooperative Officer</th></tr>
<tr><td><input type="checkbox" name="chckbx">Yes</td></tr>
</table>
</div>
<br>
<div class="button">
<center><input type="submit" value="Submit">
<input type="reset" value="Clear All">
</center>
</div>
</form>
</body>
</html>
here is the code i wrote in php but it's incomplete. some php is empty because i don't know what to code in there. in interest is loan amount multiply by 5%, the total amount is loan amount plus the interest and monthly dues is total loan amount divide by months in radio button choice.and if the "cooperative officer" checkbox is not selected the interest should be 10%.
<!doctype html>
<html lang= "en">
<head><title>Registration Form</title>
<style>
.Cn{
text-align:center;
color:#1e90ff;
font-family:Arial, Helvetica, sans-serif;
}
.add{
color:black;
font-family:Arial, Helvetica, sans-serif;
}
.h1{
text-align:center;
color:black;
font-family:Arial, Helvetica, sans-serif;
}
table, th, td {
border: 1px solid black;
align:center;
}
table.center{
margin-left:auto;
margin-right:auto;
}
table {
border-collapse: collapse;
}
</style>
</head>
<body>
<h2 class="Cn">Loan</h2>
<center class="add">blah City<br>
Mobile Number: 12345678900 <br> Telephone:(08)9999999
</center>
<hr style="Width:100%;color:#dc143c">
<h1 class="h1">Loan Information</h1>
<table class="center">
<tr><td>Date</td>
<td><?php echo date('F d, Y'); ?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo $_POST["name"];?></td>
</tr>
<tr>
<td>Address</td>
<td><?php echo $_POST["address"];?></td>
</tr>
<tr>
<td>Contact</td>
<td><?php echo $_POST["contact"]; ?></td>
</tr>
<tr>
<td>Amount</td>
<td><?php if(isset($_POST['r1'])){
$amount = $_POST['r1'];
echo $amount;
}
?></td>
</tr>
<tr>
<td>Terms of Payment</td>
<td><?php if(isset($_POST['r2'])){
$months = $_POST['r2'];
echo $months;
}
?></td>
</tr>
<tr>
<td>Interest (5%)</td>
<td><?php ?></td>
</tr>
<tr>
<td>Total Amount</td>
<td><?php ?>;</td>
</tr>
<tr>
<td>Monthly Dues</td>
<td><?php echo $_POST[""]?>;</td>
</tr>
</table>
<center>
<input type="submit" value="Submit"> <br>
<input type="submit" value ="back">
</center>
</body>
</html>
First of all, make the value of your radio buttons with the amount of the loan pure integers (5000, 10000, ...), do the same for the duration of the loan (6, 12, 24).
After you can calculate the values like this:
$interest = isset($_POST['chckbx']) ? 0.1 : 0.05; // 10% interest rate if checkbox is checked, else 5%
$interestValue = $_POST['r1'] * $interest;
$totalAmount = $_POST['r1'] + $interestValue;
$monthlyDue = $totalAmount / $_POST['r2'];
You can format the money values using number_format:
$moneyValue = 'Php ' . number_fomat($value, 2, '.', ',');

sending a variable from one php file to another and for displaying the variable value in a third file

bookincome.php takes in a couple of inputs and bi.php calculates the total net income based on the values taken from bookincome.php and displays a table that contains all the given values from the user and the calculated total book income($tnibeforetax) value. Now I have a table in my report1.php and i want to display the calulated $tnibeforetax value in it and i am not able to display the value in that table in report1.php. Please help
The code for bookincome.php :
<?php
// start session
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title> Book Income </title>
</head>
<body>
<center>
<h2>BOOK INCOME AS PER TRIAL BALANCE ENTRY </h3>
</center>
<form name='form' action="bi.php" method='post' autocomplete='off' target="_blank" [....]>
<table cellspacing="10">
<tr>
<br>
<td align="left">Book Income as per Trial Balance: </td>
<td><input type="number" name="bi" value="<?php if(isset($_POST['bi'])) ?>"></td>
</tr>
<tr>
<br>
<td align="left">Late Adjustment 1: </td>
<td><input type="number" name="la1" value="<?php if(isset($_POST['la1'])) ?>"></td>
</tr>
<tr>
<br>
<td align="left">Late Adjustment 2: </td>
<td><input type="number" name="la2" value="<?php if(isset($_POST['la2'])) ?>"><br> </td>
</tr>
<tr>
<br>
<td align="left">Late Adjustment 3: </td>
<td><input type="number" name="la3" value="<?php if(isset($_POST['la3'])) ?>"><br> </td>
</tr>
<tr>
<br>
<td align="left">Audit Adjustment 1: </td>
<td><input type="number" name="aa1" value="<?php if(isset($_POST['aa1'])) ?>"><br> </td>
</tr>
<tr>
<br>
<td align="left">Audit Adjustment 2: </td>
<td><input type="number" name="aa2" value="<?php if(isset($_POST['aa2'])) ?>"><br> </td>
</tr>
<tr>
<br>
<td align="left">Audit Adjustment 3: </td>
<td><input type="number" name="aa3" value="<?php if(isset($_POST['aa4'])) ?>"><br> </td>
</tr>
</table>
<br>
<center> <button type="submit" value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button> </center>
</form>
</body>
</html>
Following is the code of bi.php:
<?php
// start session
session_start();
$bi = $_POST['bi'];
$la1 = $_POST['la1'];
$la2 = $_POST['la2'];
$la3 = $_POST['la3'];
$aa1 = $_POST['aa1'];
$aa2 = $_POST['aa2'];
$aa3 = $_POST['aa3'];
$tnibeforetax= $bi + $la1 + $la2 + $la3 + $aa1 + $aa2 + $aa3;
$_SESSION['tnibeforetax'] = $tnibeforetax;
?>
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="width:50%" align="center">
<tr>
<td width="70%"> </td>
<td align="center"> Amount </td>
</tr>
<tr>
<td> Book Income as per trail Balance </td>
<td align="right">
<?php echo $bi ; ?> </td>
</tr>
<?php
if($la1!=0)
{
echo '<tr><td> Late Adjustment1 </td> ';
echo '<td align="right">'. $la1 . '</td><tr>';
}
?>
<?php
if($la2!=0)
{
echo '<tr><td> Late Adjustment2 </td>';
echo '<td align="right">'. $la2 . '</td></tr>';
}
?>
<?php
if($la3!=0)
{
echo '<tr><td> Late Adjustment3 </td> ';
echo '<td align="right">'. $la3 . '</td></tr>';
}
?>
<?php
if($aa1!=0)
{
echo '<tr><td> Audit Adjustment1 </td> ';
echo '<td align="right">'. $aa1 . '</td></tr>';
}
?>
<?php
if($aa2!=0)
{
echo '<tr><td> Audit Adjustment2 </td></tr> ';
echo '<tr><td align="right">'. $aa2 . '</td></tr>';
}
?>
<?php
if($aa3!=0)
{
echo '<tr><td> Audit Adjustment3 </td>';
echo '<td align="right">'. $aa3 . '</td></tr>';
}
?>
<tr>
<td> Total Net Income before tax as per Income Statement </td>
<td align="right">
<?php echo $tnibeforetax ; ?> </td>
</tr>
The code for report1.php:
<?php
// start session
session_start();
$tnibeforetax = $_SESSION['$tnibeforetax'];
?>
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td
{
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="width:50%" align="center" >
<tr>
<td style="font-weight:bold" colspan="2" ><font color="darkgreen" > Income from Business & Proffession:</td></font>
</tr>
<tr>
<td> Net Income before tax as per Income Statement </td>
<td width="25%"> <?php echo "$" . $tnibeforetax; ?></td>
</tr>
You are just checking not checking and printing so change here and for all below
<td><input type="number" name="bi" value="<?php $_POST['bi'] ?? '' ?>"></td>
Here $_POST['bi'] ?? '' is same for isset($_POST['bi']) ? $_POST['bi'] : '' in php 7.
Add same check for bi.php
$bi = $_POST['bi'] ?? 0;
The reason why it's not working is because you set the session with value tnibeforetax but getting it with $tnibeforetax please replace the above code in your 3rd file i.e report1.php.
<?php
// start session
session_start();
$tnibeforetax = $_SESSION['tnibeforetax'];
?>
You forgot to add the output of the result inside the value attribute.
<td><input type="number" name="bi" value="<?php $_POST['bi'] ?? '' ?>"></td> to
<td><input type="number" name="bi" value="<?php echo isset($_POST['bi']) ? $_POST['bi'] : '' ?>"></td>
The same for la1, la2 etc.
With short_open_tag=On in php.ini file it can be just <?= isset($_POST['bi']) ? $_POST['bi'] : '' ?>. In PHP 7 it can be just <?= $_POST['bi'] ?? '' ?>.
$tnibeforetax = $_SESSION['$tnibeforetax']; in report1.php must be
$tnibeforetax = $_SESSION['tnibeforetax'];
Please use more understandable names for variables. The name of the variable must match the data stored in it as clearly as possible. For ex., instead of bi use bookIncome.
$tnibeforetax = $_SESSION['$tnibeforetax'];
No $ inside the value.
please remove the $ sign from ['$tnibeforetax'] that is written as $tnibeforetax = $_SESSION['$tnibeforetax'] in report1 code section

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.

I am trying to make a Edit form Using PHP

My html code but saved as Modyfyitems.php
<?include 'Login/login_check.php';?>
<?include 'inc/Application.php';?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<style type="text/css">
body {
background-color: #284489;
text-shadow: 0px 0px #FFFFFF;
color: #FFFFFF;
}
form1 {
background-color: #FFFFFF
}
</style>
<link rel="stylesheet" type="text/css" media="all" href="css/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="js/jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
new JsDatePick({
useMode:2,
target:"datereceived",
dateFormat:"%d-%M-%Y"
});
};
</script>
</head>
<body>
<h2> </h2>
<form id="form1" name="form1" aling="center" method="post">
<div align="center">
<table width="393" border="0">
<tr>
<td><div align="center">
<h2><span style="text-align: left; color: #FFFFFF;">LAC Product Registery</span></h2>
</div></td>
</tr>
</table>
<p>
<input type="button" name="button4" id="button4" onClick="location.href='Menu.php'" value="Menu">
</p>
</div>
<div align="center" style="background-color: #FFFFFF; color: #000000;">
<table width="827" border="0" align="center">
<tr bgcolor="#FDFDFD">
<td width="501"><h3>Modify Items</h3>
<p>Enter Code
<input name="barcode" type="text" autofocus required="required" id="barcode" form="form1">
<input type="submit" name="search" id="search" onClick="location.href='Actions/loaditem.php'" value="Search">
</p>
<table width="500" border="0" cellpadding="10" cellspacing="1">
<tr>
<td width="141" bgcolor="#E8F1FC">Sponsor</td>
<td width="316" bgcolor="#E8F1FC"><?include 'Actions/loadLists/sponsor.php';?></td>
</tr>
<tr>
<td bgcolor="#f1f4f9">Date Received</td>
<td bgcolor="#f1f4f9"><input type="datetime" name="datereceived" value="<? echo $DateReceived; ?>" id="datereceived" placeholder="17-FEB-2014"></td>
</tr>
<tr>
<td bgcolor="#E8F1FC"><strong>Code</strong></td>
<td bgcolor="#E8F1FC"> </td>
</tr>
<tr>
<td bgcolor="#F1F4F9"><ul>
<li> Container</li>
</ul></td>
<td bgcolor="#F1F4F9"><input name="container" type="number" value="<? echo $Container; ?>" id="container" placeholder="0152"></td>
</tr>
<tr>
<td bgcolor="#E8F1FC"><ul>
<li>Pallet</li>
</ul></td>
<td bgcolor="#E8F1FC"><input name="pallet" type="number" value="<? echo $Pallet; ?>" id="number5" placeholder="0028"></td>
</tr>
<tr>
<td bgcolor="#F1F4F9"><ul>
<li>Amount</li>
</ul></td>
<td bgcolor="#F1F4F9"><input name="amount" type="number" id="number6" value="<? echo $Amount; ?>" placeholder="0002"></td>
</tr>
<tr>
<td bgcolor="#E8F1FC">Description</td>
<td bgcolor="#E8F1FC"><?include 'Actions/loadLists/descriptions.php';?></td>
</tr>
<tr>
<td bgcolor="#F1F4F9">Remarks</td>
<td bgcolor="#F1F4F9"><textarea name="remarks" id="remarks"><? echo $Remarks; ?></textarea></td>
</tr>
<tr>
<td bgcolor="#E8F1FC">Location</td>
<td bgcolor="#E8F1FC"><?include 'Actions/loadLists/locations.php';?></td>
</tr>
<tr>
<td height="18"> </td>
<td> </td>
</tr>
</table></td>
<td width="316" valign="top" style="text-align: left"><p><br>
</p>
<p> Documents</p>
<p> </p></td>
</tr>
</table>
</div>
<table width="383" border="0" align="center">
<tr>
<td width="377" style="text-align: center"><input type="button" name="button" id="button" value="Save">
...
<input type="button" name="button6" id="button6" onClick="location.href='Menu.php'" value="Cancel">
...
<input type="button" name="button2" id="button2" value="Delete">
...
<input type="button" name="button3" id="button3" value="Print Barcode"> </td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
</form>
<p> </p>
<p> </p>
</body>
</html>
Here is my PHP script
<?
$conn = mysql_connect('localhost', 'root', 'root');
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("LAC", $conn);
$Barcode =$_REQUEST['barcode'];
$result = mysql_query("SELECT * FROM Lists WHERE Barcode = '$Barcode'");
$row = mysql_fetch_array($result);
if (!$result)
{
die("Error: Data not found..");
}
$Barcode = $row['Barcode'];
$Sponsor = $row['Sponsor'];
$DateReceived = $row['DateReceived'];
$Container = $row['Container'];
$Pallet = $row['Pallet'];
$Amount = $row['Amount'];
$Description = $row['Description'];
$Remarks = $row['Remarks'];
$Location = $row['Location'];
mysql_close($conn);
?>
So Basically I am trying to load all the text boxes and drop down boxes from the database when the correct barcode is entered and the search button is hit.
For some reason when I hit the search button it doesn't load anything it just reloads the page.
I am new to php but have programming experience in vb.net
I think your are initializing variables after fetching values from the database in PHP script. so the scope of those variable is only withing that file. So, I guess if you include that file in modifyitem.php, this would work.
thank you.

Printing website correctly

I am trying to make a website that reads from a csv file and render the data on the screen in a printable format (it is for printing tickets). The page creates 2 tickets per row and loops threw until it runs out of data. It all works perfectly and looks just the way i want it but, when i print it the 3rd row down has one of the rows of text move up onto the line above it. My question is how can i make it print the way it is seen on the screen and why would it screw up only the 3rd row when all rows are made with the same code.
Thanks
EDIT:
while (!feof($file_handle)){`
$csvText = fgetcsv($file_handle, 1024);
$username = $csvText[1];
$password = $csvText[2];
$profile = $csvText[3];
$daysValid = $csvText[4];
$expiry = $csvText[5];
if($pos == 0)
{
if($count == 5){
echo "<p><br /></p>";
$count = 0;
}else{
$count++;
}
echo "<div class='itemRow'>";
echo "<div class='left'>";
$pos = 1;
?>
<h4 class="centre">Internet Access Voucher</h4>
<img class="image" src="./icon.jpg" />
<div class="info">
<table>
<tr>
<td>
Username
</td>
</tr>
<tr>
<td>
Password
</td>
</tr>
<tr>
<td>
Profile
</td>
</tr>
<tr>
<td>
Valid for
</td>
</tr>
<tr>
<td>
Expiry date
</td>
</tr>
</table>
</div>
<div class="uniqueInfo">
<table>
<tr>
<td>
<?php echo $username;?>
</td>
</tr>
<tr>
<td>
<?php echo $password;?>
</td>
</tr>
<tr>
<td>
<?php echo $profile;?>
</td>
</tr>
<tr>
<td>
<?php echo $daysValid;?>
</td>
</tr>
<tr>
<td>
<?php echo $expiry;?>
</td>
</tr>
</table>
</div>
<p class="centre"><br />Please remember to disconnect to stop each session.</p>
</div>
<br />
<?php
} else {
?>
<div class="right">
<h4 class="centre">Internet Access Voucher</h4>
<img class="imageRight" src="./icon.jpg" />
<div class="infoRight">
<table>
<tr>
<td>
Username
</td>
</tr>
<tr>
<td>
Password
</td>
</tr>
<tr>
<td>
Profile
</td>
</tr>
<tr>
<td>
Valid for
</td>
</tr>
<tr>
<td>
Expiry date
</td>
</tr>
</table>
</div>
<div class="uniqueInfoRight">
<table>
<tr>
<td>
<?php echo $username;?>
</td>
</tr>
<tr>
<td>
<?php echo $password;?>
</td>
</tr>
<tr>
<td>
<?php echo $profile;?>
</td>
</tr>
<tr>
<td>
<?php echo $daysValid;?>
</td>
</tr>
<tr>
<td>
<?php echo $expiry;?>
</td>
</tr>
</table>
</div>
<p class="centre"><br />Please remember to disconnect to stop each session.</p>
</div>
</div>
<?php
$pos = 0;
}
}
?>
CSS
.centre
{
text-align:center;
}
.itemRow
{
position:relative;
top:0px;
}
.left
{
width:500px;
position:relative;
font-family:Comic Sans, Comic sans MS, cursive;
/*border-style:solid;
border-width:1px;*/
}
.right
{
width:500px;
position:absolute;
left:600px;
top:-20px;
font-family:Comic Sans, Comic sans MS, cursive;
/*(border-style:solid;
border-width:1px;*/
}
.image
{
position:absolute;
top:70px;
}
.info
{
position:relative;
left:63px;
}
.uniqueInfo
{
position:absolute;
left:250px;
top:42px;
}
.infoRight
{
position:relative;
left:63px;
top:0px;
}
.uniqueInfoRight
{
position:absolute;
left:250px;
top:65px;
}
.imageRight
{
position:absolute;
top:90px;
}
I suspect this might be the problem:
if($count == 5){
echo "<p><br /></p>";
You have 2 per row, and increment $count after every ticket. So, $count = 5 would be after the fourth ticket, or when the third row starts. A sample HTML page would give me a better idea of what's going on exactly, but I'd suggest doing something like
<br style="clear: both;" />
between the rows to split them cleanly. So before ticket 3 and 5 ($count = 3 and $count = 5).

Categories