<?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

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

wow! thanks a lot.. lemme try....

and it worked.. hurrayyyyyyy

<?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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.