I this codes to join two tables in my database. It didn't show any error message when trying to echo it using while loop, but also it shows nothing. Can anyone help me please?
$sql = "SELECT * FROM usr_details, paymnt_details WHERE usr_details.Trnsnubr = paymnt_details.Trnsnubr";
$sql =
"SELECT *
FROM usr_details
JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr";
This is my html and PHP code for echoing:
$rs_result = mysql_query ($sql) or die(mysql_error());
<table width="100%" height="109" border="1" cellpadding="2px" >
<tr>
<td colspan="5" class="mainheader">Registerd Persons</td>
<td> </td>
<td> </td>
<td> </td>
<td colspan="16"></td>
</tr>
<tr>
<td class="tableheader" width="68">Payment</td>
<td class="tableheader" width="64">Amount</td>
<td class="tableheader" width="58">Date</td>
<td class="tableheader" width="74">Trnsnubr</td>
<td class="tableheader" width="97"> Paymenttyp </td>
<td class="tableheader" width="59">Room Type</td>
<td class="tableheader" width="96"> Packgname </td>
<td class="tableheader" width="142">Full name</td>
<td class="tableheader" width="1"> Email </td>
<td class="tableheader" width="1">Mobile </td>
<td class="tableheader" width="1">Address</td>
<td class="tableheader" width="1">Country</td>
<td class="tableheader" width="40">Mem_num</td>
<td class="tableheader" width="40">Chptr</td>
<td class="tableheader" width="40">Ral</td>
<td class="tableheader" width="40">ex-mem-1-name</td>
<td class="tableheader" width="40">ex-mem-2-name</td>
<td class="tableheader" width="40">Faly-mem-1-name</td>
<td class="tableheader" width="40">Faly-mem-2-name</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($rs_result)) {
$amount=$row["amount"];
$successness=$row["successness"];
$Timestamp=$row["Timestamp"];
$fname=$row["fname"];
$lname=$row["lname"];
$memnumbr=$row["memnumbr"];
$chptrpostion=$row["chptrpostion"];
$ralpositin=$row["ralpositin"];
$adrs1=$row["adrs1"];
$adrs2=$row["adrs2"];
$city=$row["city"];
$cntry=$row["cntry"];
$MTelNo=$row["MTelNo"];
$email=$row["email"];
$Trnsnubr=$row["Trnsnubr"];
$packgname=$row["packgname"];
$rtype=$row["rtype"];
$paymenttyp=$row["paymenttyp"];
$exmem1name=$row["exmem1name"];
$exmem2name=$row["exmem2name"];
$familymem1name=$row["familymem1name"];
$familymem2name=$row["familymem2name"];
?>
<tr>
<td> dfgdfgfdgdfgdg<?php echo $successness;?></td>
<td> <?php echo $amount;?></td>
<td> <?php echo $Timestamp;?></td>
<td> <?php echo $Trnsnubr;?></td>
<td> <?php echo $paymenttyp;?></td>
<td> <?php echo $rtype;?></td>
<td> <?php echo $packgname;?></td>
<td> <?php echo $fname." ".$lname;?></td>
<td> <?php echo $email;?></td>
<td> <?php echo $MTelNo;?></td>
<td> <?php echo $adrs1." ".$adrs2." ".$city;?></td>
<td> <?php echo $cntry;?></td>
<td> <?php echo $memnumbr;?></td>
<td> <?php echo $chptrpostion;?></td>
<td> <?php echo $ralpositin;?></td>
<td> <?php echo $exmem1name;?></td>
<td> <?php echo $exmem2name;?></td>
<td> <?php echo $familymem1name;?></td>
<td> <?php echo $familymem2name;?></td>
</tr>
<?php
};
?>
</table>
This is my whole coding file:
<?php session_start();
$user_name = $_SESSION['username'];
$user_pass = $_SESSION['password'];
if ( $user_name == '' ) {
header('location:login.php');
exit();
}
?>
<?php require_once('connection.php'); ?>
<?php require_once('function.php'); ?>
<!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>Untitled Document</title>
<link href="css/main.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/users.css" rel="stylesheet" type="text/css" media="all" />
<link href="../dojo/dojo/resources/dojo.css" type="text/css" media="all" />
<link href="../dojo/dijit/themes/nihilo/nihilo.css" type="text/css" media="all" />
<script type="text/javascript" src="../dojo/dojo/dojo.js" ></script>
<script src="js/navigation.js" type="text/javascript"></script>
<script type="text/javascript">
</script>
<style type="text/css">
.tableheader {
font-size: 18px;
font-weight: bold;
color: #96C;
}
.mainheader {
font-size: 24px;
font-weight: bolder;
color: #09F;
}
</style></head>
<body class="nihilo">
<span class="tableheader"></span>
<div id="wrap">
<!-- Enable when Ajax is loading -->
<div id="loading_wrap"></div>
<div id="loading"><img src="images/loading.gif" width="32" height="32" alt="loading" /><br />Loading...</div>
<!-- End loading -->
<div id="head">
<div id="subHead"></div>
</div>
<div id="main">
<?php
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$limit= 5;
$start_from = ($page-1) * $limit;
//$sql = "SELECT * FROM usr_details ORDER BY Trnsnubr ASC LIMIT $start_from, $limit ";
//$sql = "SELECT * FROM usr_details, paymnt_details WHERE usr_details.Trnsnubr = paymnt_details.Trnsnubr";
/*$sql =
"SELECT *
FROM usr_details
JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr";*/
$sql = "SELECT usr_details.*, paymnt_details.amount, paymnt_details.successness
FROM usr_details
JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr";
$rs_result = mysql_query ($sql) or die(mysql_error());
?>
<table width="100%" height="109" border="1" cellpadding="2px" >
<tr>
<td colspan="5" class="mainheader">Registerd Persons</td>
<td> </td>
<td> </td>
<td> </td>
<td colspan="16"></td>
</tr>
<tr>
<td class="tableheader" width="68">Payment</td>
<td class="tableheader" width="64">Amount</td>
<td class="tableheader" width="58">Date</td>
<td class="tableheader" width="74">Trnsnubr</td>
<td class="tableheader" width="97"> Paymenttyp </td>
<td class="tableheader" width="59">Room Type</td>
<td class="tableheader" width="96"> Packgname </td>
<td class="tableheader" width="142">Full name</td>
<td class="tableheader" width="1"> Email </td>
<td class="tableheader" width="1">Mobile </td>
<td class="tableheader" width="1">Address</td>
<td class="tableheader" width="1">Country</td>
<td class="tableheader" width="40">Mem_num</td>
<td class="tableheader" width="40">Chptr</td>
<td class="tableheader" width="40">Ral</td>
<td class="tableheader" width="40">ex-mem-1-name</td>
<td class="tableheader" width="40">ex-mem-2-name</td>
<td class="tableheader" width="40">Faly-mem-1-name</td>
<td class="tableheader" width="40">Faly-mem-2-name</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($rs_result)) {
$amount=$row["amount"];
$successness=$row["successness"];
$Timestamp=$row["Timestamp"];
$fname=$row["fname"];
$lname=$row["lname"];
$memnumbr=$row["memnumbr"];
$chptrpostion=$row["chptrpostion"];
$ralpositin=$row["ralpositin"];
$adrs1=$row["adrs1"];
$adrs2=$row["adrs2"];
$city=$row["city"];
$cntry=$row["cntry"];
$MTelNo=$row["MTelNo"];
$email=$row["email"];
$Trnsnubr=$row["Trnsnubr"];
$packgname=$row["packgname"];
$rtype=$row["rtype"];
$paymenttyp=$row["paymenttyp"];
$exmem1name=$row["exmem1name"];
$exmem2name=$row["exmem2name"];
$familymem1name=$row["familymem1name"];
$familymem2name=$row["familymem2name"];
?>
<tr>
<td> <?php echo $successness;?></td>
<td> <?php echo $amount;?></td>
<td> <?php echo $Timestamp;?></td>
<td> <?php echo $Trnsnubr;?></td>
<td> <?php echo $paymenttyp;?></td>
<td> <?php echo $rtype;?></td>
<td> <?php echo $packgname;?></td>
<td> <?php echo $fname." ".$lname;?></td>
<td> <?php echo $email;?></td>
<td> <?php echo $MTelNo;?></td>
<td> <?php echo $adrs1." ".$adrs2." ".$city;?></td>
<td> <?php echo $cntry;?></td>
<td> <?php echo $memnumbr;?></td>
<td> <?php echo $chptrpostion;?></td>
<td> <?php echo $ralpositin;?></td>
<td> <?php echo $exmem1name;?></td>
<td> <?php echo $exmem2name;?></td>
<td> <?php echo $familymem1name;?></td>
<td> <?php echo $familymem2name;?></td>
</tr>
<?php
};
?>
</table>
</div>
<div id="footer">
<?php include("footer.php"); ?>
</div>
</div>
</body>
</html>
If these tables have columns with the same name this request will cause an error. It's happens coz you tried get all values by column name. try to not use * in difficult queries.
Try do like this:
SELECT usr_details.*, paymnt_details.field1, paymnt_details.field2
FROM usr_details
JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr
1
<?
$res = mysql_query("SELECT * FROM usr_details LIMIT 1");
var_dump( mysql_fetch_assoc($res) );
$res = mysql_query("SELECT * FROM paymnt_details LIMIT 1");
var_dump( mysql_fetch_assoc($res) );
$sql = "SELECT usr_details.* FROM usr_details LEFT JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr";
$res = mysql_query($sql);
var_dump($res);
while($row=mysql_fetch_assoc($res)) {
var_dump($row);
}
var_dump( mysql_error() );
?>
Related
**Look at the picture **
I want to see the page without 'Notice:' because here all the result I think works finely. But why does it shows. Any Mistake? Please help me.
The code is like:
<?php
mysql_connect("localhost","root");
mysql_select_db("simple");
$id=$_POST['id'];
$res=mysql_query("SELECT * FROM simple_tb WHERE id=$id");
while($row=mysql_fetch_array($res))
{
?>
<link rel="stylesheet" type="text/css" href="demo.css" media="screen" /></head>
<h1 align="center"> ABC IDEAL SCHOOL AND COLLEGE</h1>
<h3 align="center">Baraiyahat, Chittagong, 01772969874 </h3>
<p align="center">Students Tuetion Fee Payment Sheet<br></p>
<table class="table" align="center"width="800" bgcolor="skyblue">
<tr><td width="25%">ID No:</td><td width="25%"><?php echo $row['id'];?></td></tr>
<tr><td>Name:</td> <td><?php echo $row['n'];?></td></tr>
<tr><td>Class:</td><td><?php echo $row['c'];?></td></tr>
<tr><td>Roll:</td> <td><?php echo $row['r'];?></td></td></tr>
</table>
<br>
<h4 ALIGN="CENTER">PAYMENT STATUS</H4>
<table align="center"width="800" BORDER="1" bgcolor="red">
<tr>
<td align="center"><B>DATES</B></td>
<td align="center"><B>DESCRIPTION</B></td>
<td align="center"><B>MEMO NO</B></td>
<td align="center"><B>BDT</B></td>
<td align="center"><B>Con.Total</B></td>
</tr>
<?php
$res2=mysql_query("SELECT * FROM ac WHERE sid=".$row['id']);
while($row2=mysql_fetch_array($res2))
{ $sum+= $row2['t'];
?>
<tr bgcolor="cream">
<td bgcolor="white"align="center"><?php echo $row2['d'];?></td>
<td bgcolor="white"align="center"><?php echo $row2['des'];?></td>
<td bgcolor="white"align="center"><?php echo $row2['m'];?></td>
<td bgcolor="white"align="center"><?php echo $row2['t'];?></td>
<td bgcolor="white"align="center"><?php echo $sum."<br>";?></td>
<td bgcolor="white"align="center"></td>
</tr>
<?php
}
?></table><?php
}
Now please tell me details what can I do for the written code.
You need to assign value of sum to 0 before while loop
<?php
$sum = 0;
$res2=mysql_query("SELECT * FROM ac WHERE sid=".$row['id']);
while($row2=mysql_fetch_array($res2))
{ $sum+= $row2['t'];
?>
Try this one. You have used somewhere mysql and some where mysqli. That is one problem.
<?php
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"simple");
$id=$_POST['id'];
$res=mysqli_query($con,"SELECT * FROM simple_tb WHERE id=$id");
while($row=mysqli_fetch_array($res))
{
?>
<link rel="stylesheet" type="text/css" href="demo.css" media="screen" />
</head>
<h1 align="center"> ABC IDEAL SCHOOL AND COLLEGE</h1>
<h3 align="center">Baraiyahat, Chittagong, 01772969874 </h3>
<p align="center">Students Tuetion Fee Payment Sheet<br></p>
<table class="table" align="center"width="800" bgcolor="skyblue">
<tr><td width="25%">ID No:</td><td width="25%"><?php echo $row['id'];?>
</td></tr>
<tr><td>Name:</td> <td><?php echo $row['n'];?></td></tr>
<tr><td>Class:</td><td><?php echo $row['c'];?></td></tr>
<tr><td>Roll:</td> <td><?php echo $row['r'];?></td></td></tr>
</table>
<br>
<h4 ALIGN="CENTER">PAYMENT STATUS</H4>
<table align="center"width="800" BORDER="1" bgcolor="red">
<tr>
<td align="center"><B>DATES</B></td>
<td align="center"><B>DESCRIPTION</B></td>
<td align="center"><B>MEMO NO</B></td>
<td align="center"><B>BDT</B></td>
<td align="center"><B>Con.Total</B></td>
</tr>
<?php
$res2=mysqli_query($con,"SELECT * FROM ac WHERE sid=".$row['id']);
while($row2=mysqli_fetch_array($res2))
{ $sum+= $row2['t'];
?>
<tr bgcolor="cream">
<td bgcolor="white"align="center"><?php echo $row2['d'];?></td>
<td bgcolor="white"align="center"><?php echo $row2['des'];?>
</td>
<td bgcolor="white"align="center"><?php echo $row2['m'];?></td>
<td bgcolor="white"align="center"><?php echo $row2['t'];?></td>
<td bgcolor="white"align="center"><?php echo $sum."<br>";?></td>
<td bgcolor="white"align="center"></td>
</tr>
<?php
}
?></table><?php
``}
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 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.
I am new in PHP. I want to create a table using loop and wants to print variables data in it fetching from Mysql. Here, I face some problems for creating table.
I want to create table like this:
But I failed in doing so.
My code is here:
<!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>
<style>
table {
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
ini_set('error_reporting', E_ALL);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pacra1";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT * FROM `letter_copy` WHERE `id` = 1";
$conn->multi_query($sql);
//$conn->next_result();
$result = $conn->use_result();
echo $conn->error;
$row = $result->fetch_assoc();
$opinion = $row['opinion'];
$action = $row['action'];
$opinion_chunks = explode(",", $opinion);
?>
<div style="margin-top:auto; width:auto;font-family:'Times New Roman', Times, serif; text-align:left; font-size:12px; text-align:center">
<table width="657">
<tr>
<td width="225"> <strong>Opinion</strong></td>
<td width="62"> <strong>Action</strong></td>
<td colspan="4"><strong>Ratings</strong></td>
<td width="54"><strong>Outlook</strong></td>
<td width="67"><strong>Rating Type</strong></td>
</tr>
<tr>
<td width="225"> </td>
<td width="62"> </td>
<td colspan="2"><b>Long Term</b></td>
<td colspan="2"><b>Short Term</b></td>
<td width="54"> </td>
<td width="67"> </td>
</tr>
<tr>
<td width="225"> </td>
<td width="62"> </td>
<td width="52"><b>Current</b></td>
<td width="45"><b>Previous</b></td>
<td width="49"><b>Current</b></td>
<td width="51"><b>Previous</b></td>
<td width="54"> </td>
<td width="67"> </td>
</tr>
</table>
</div>
<?php
echo '<table border="01">';
foreach($opinion_chunks as $row){
echo '<tr>';
$row = explode(',',$row);
$row1 = explode(",", $action);
foreach($row as $cell){
if ($cell == "")
continue;
echo '<td>';
echo $cell;
echo '</td>';
foreach($row1 as $cell1){
if ($cell1 == "")
continue;
echo '<td>';
echo $cell1;
echo '</td>';
}
}
echo '</tr>';
}
echo '</table>';
?>
</body>
</html>
And the output of my code is:
You can easily seen my problem.
Here is what you want
$q = "select * from letter_copy";
$result = execute $q to get results
<div style="margin-top:auto; width:auto;font-family:'Times New Roman', Times, serif; text-align:left; font-size:12px; text-align:center">
<table width="657" border="1" cellpadding="10" cellspacing="0">
<tr>
<td width="225"> <strong>Opinion</strong></td>
<td width="62"> <strong>Action</strong></td>
<td colspan="4"><strong>Ratings</strong></td>
<td width="54"><strong>Outlook</strong></td>
<td width="67"><strong>Rating Type</strong></td>
</tr>
<tr>
<td width="225"> </td>
<td width="62"> </td>
<td colspan="2"><b>Long Term</b></td>
<td colspan="2"><b>Short Term</b></td>
<td width="54"> </td>
<td width="67"> </td>
</tr>
<tr>
<td width="225"> </td>
<td width="62"> </td>
<td width="52"><b>Current</b></td>
<td width="45"><b>Previous</b></td>
<td width="49"><b>Current</b></td>
<td width="51"><b>Previous</b></td>
<td width="54"> </td>
<td width="67"> </td>
</tr>
<?php foreach ($result as $row) { ?>
<?php
$action = explode(",", $row->action);
$long_term = explode(",", $row->long_term_rating);
$short_term = explode(",", $row->short_term_rating);
$outlook = explode(",", $row->outlook);
for ($i = 0; $i < count($action); $i++) {
?>
<tr>
<td><?= $row->opinion ?></td>
<td><?= $action[$i] ?></td>
<td><?= $long_term[$i] ?></td>
<td><?= $long_term[$i] ?></td>
<td><?= $short_term[$i] ?></td>
<td><?= $short_term[$i] ?></td>
<td><?= $outlook[$i] ?></td>
<td><?= $row->rating_type_title ?></td>
</tr>
<?php }
}
?>
</table>
i did it by this code
<!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>
<style>
table {
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
ini_set('error_reporting', E_ALL);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pacra1";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT * FROM letter_copy WHERE id = 3";
$conn->multi_query($sql);
//$conn->next_result();
$result = $conn->use_result();
?>
<div style="margin-top:auto; width:auto;font-family:'Times New Roman', Times, serif; text-align:left; font-size:12px">
<table width="657">
<tr>
<td width="225"> <strong>Opinion</strong></td>
<td width="62"> <strong>Action</strong></td>
<td colspan="4" style="text-align:center"><strong> Ratings</strong></td>
<td width="54"><strong>Outlook</strong></td>
<td width="67"><strong>Rating Type</strong></td>
</tr>
<tr>
<td width="225"> </td>
<td width="62"> </td>
<td colspan="2"><b>Long Term</b></td>
<td colspan="2"><b>Short Term</b></td>
<td width="54"> </td>
<td width="67"> </td>
</tr>
<tr>
<td width="225"> </td>
<td width="62"> </td>
<td width="52"><b>Current</b></td>
<td width="45"><b>Previous</b></td>
<td width="49"><b>Current</b></td>
<td width="51"><b>Previous</b></td>
<td width="54"> </td>
<td width="67"> </td>
</tr>
<?php foreach ($result as $row) { ?>
<?php
//$a = $row['action'];
$action = explode(",", $row['action']);
$long_term = explode(",", $row['long_term_rating']);
$p_long_term = explode(",", $row['p_long_term_rating']);
$short_term = explode(",", $row['short_term_rating']);
$p_short_term = explode(",", $row['p_short_term_rating']);
$outlook = explode(",", $row['outlook']);
$opinion = explode(",", $row['opinion']);
$rating_type = explode(",", $row['rating_type']);
for ($i = 0; $i < count($opinion); $i++) {
if ($opinion[$i] == "")continue;
?>
<tr>
<td><?= $opinion[$i] ?> </td>
<td><?= $action[$i] ?> </td>
<td><?= $long_term[$i] ?> </td>
<td><?= $p_long_term[$i] ?> </td>
<td><?= $short_term[$i] ?></td>
<td><?= $p_short_term[$i] ?></td>
<td><?= $outlook[$i] ?> </td>
<td><?= $rating_type[$i]?></td>
</tr>
<?php }
}
?>
</table>
</div>
</body>
</html>
I am working on my PHP code (insert_post.php) and I have two errors:
**Warning: move_uploaded_file(news_images/RaiderX.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\my_cms\admin\insert_post.php on line 106
Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php60F7.tmp' to 'news_images/RaiderX.jpg' in C:\xampp\htdocs\my_cms\admin\insert_post.php on line 106**
Everything is fine and I can see that data (images) is coming through to my mysql database but I cannot understand why there are these two errors.
This is the code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
td, td {
padding:0px;
margin:0px;
}
</style>
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>tinymce.init({selector:'textarea'});</script>
</head>
<body>
<form action="insert_post.php" method="post" enctype="multipart/form-data">
<table width="800" align="center" border="2">
<tr bgcolor="#F47302">
<td colspan="6" align="center"><h1>Insert New Post</h1></td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Title:</strong></td>
<td><input type="text" name="post_title" size="40"</td>
</tr>
<tr>
<td align="right"bgcolor="F47302" ><strong>Post Categories:</strong></td>
<td>
<select name="cat">
<option value="null">Select a Category</option>
<?php
include("../includes/database.php");
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while ($cats_row=mysqli_fetch_array($run_cats)) {
$cat_id=$cats_row['cat_id'];
$cat_title=$cats_row['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Author:</strong></td>
<td><input type="text" name="post_author" size="40"</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Keywords:</strong></td>
<td><input type="text" name="post_keywords" size="50"</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Image:</strong></td>
<td><input type="file" name="post_image" size="50"</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Content:</strong></td>
<td><textarea name="post_content" rows="15" cols="60"></textarea></td>
</tr>
<tr>
<td colspan="6" align="center" bgcolor="F47302"><input type="submit" name="submit" value="Publish Now"</td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
$post_title = $_POST['post_title'];
$post_date = date('m-d-y');
$post_cat = $_POST['cat'];
$post_author = $_POST['post_author'];
$post_keywords = $_POST['post_keywords'];
$post_image = $_FILES['post_image'] ['name'];
$post_image_tmp = $_FILES['post_image']['tmp_name'];
$post_content = $_POST['post_content'];
if($post_title=='' OR $post_cat=='null' OR $post_author=='' OR $post_keywords=='' OR $post_image=='' OR $post_content==''){
echo "<script>alert('Please fill in all the fileds')</script>";
exit();
}
else {
move_uploaded_file($post_image_tmp,"news_images/$post_image");
$insert_posts = "insert into posts (category_id,post_title,post_date,post_author,post_keywords,post_image,post_content) values ('$post_cat','$post_title','$post_date','$post_author','$post_keywords','$post_image','$post_content')";
$run_posts = mysqli_query($con,$insert_posts);
echo "<script>alert('Post Has been Published!')</script>";
echo "<script>window.open('index.php?insert_post','_self')</script>";
}
}
?>
check
$_FILES["post_image"]["error"]
for any sort of upload error first, this may give you a better idea of why this is happening and also catch the problem so you don't cache the info of a missing file in your DB