1
<?php
$con=mysqli_connect("localhost","root","","trial");

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
if(isset($_POST['submit']))
{
$billno=$_POST['billno'];

$doa=$_POST['doa'];
$dod=$_POST['dod'];
$dbcd=$_POST['dbcd'];
$acno=$_POST['acno'];
$dosub=$_POST['dosub'];
$suby=$_POST['suby'];
$dop=$_POST['dop'];
$credate=$_POST['credate'];
$paytype=$_POST['paytype'];


$sql="UPDATE cust SET doa ='$doa', dod = '$dod', dbcd='$dbcd', acno='$acno', dosub='$dosub', suby='$suby', dop='$dop', credate='$credate' 
  ** WHERE billno = '$billno'";**
print $sql;


if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }


}

echo "1 record edited";

mysqli_close($con);
?>

my data base (cus) is not getting updated as the bill no while for WHERE clause gives a blank space before and after the fetched result

2
Contributors
5
Replies
28
Views
3 Years
Discussion Span
Last Post by cereal
0

After:

if(isset($_POST['submit']))
{

Insert:

$_POST = array_map('trim', $_POST);

If, instead, you want to apply it only to one variable then write only this:

$billno = trim($_POST['billno']);

Ref: http://www.php.net/trim

Edited by cereal

0
<?php  
$con=mysqli_connect("localhost","root","","trial");

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";  
echo "<tr style='font-weight: bold;'>";  
echo "<td width='200' align='center'>Customer</td><td width='200' align='center'>Amount</td>";  
echo "</tr>";  
if(isset($_POST['submit']))
{

$custype = $_POST['custype'];

$from = $_POST['from'];

$to = $_POST['to'];
echo "<br><br>";
echo " <h2> Grand Total of ".$_POST['custype']. " from " .$_POST['from']. " to " .$_POST['to']. "</h2>";
$result = mysqli_query($con,"SELECT custype,SUM(amt) FROM cust WHERE custype = '$custype' AND DATE(day) >='$from' AND DATE(day) <='$to'");

while($row=mysqli_fetch_array($result))  
{  
echo "<tr>";  
echo "<td align='center' width='200'>" . $row['custype'] . "</td>";  
echo "<td align='center' width='200'>" . $row[1] . "</td>";  

echo "</tr>";  
} 

echo "</table>";  

}
mysqli_close($con);
?>  

need to export this output to a csv file.. what all code to be added?? i am totally new to php.. pls help
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.