Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

not getting value from table

Status
Not open for further replies.

ckdoublenecks

Programmer
Dec 28, 2010
9
0
0
US
I'm trying to read the taxrate from the database table and use it with values from another table. the database and table are correct as is the field (taxrate) from the table, value is 0.06. Then I'm trying to multiply that value by the value of a field from another table (charges) then update the table . since it doesn't update, I tried echoing the two values but 0 is displayed for both. Will someone advise me?
<?php
mysql_connect("localhost","root","");
mysql_select_db(numbersdb) or die( "Unable to select database");
$query = "SELECT taxrate FROM numbdata ";
mysql_fetch_assoc(mysql_query($query));
$result=mysql_query($query);
// include("getpercent.php");
$taxrate = $_POST['taxrate'];
echo "taxrate ".$data['taxrate'];

mysql_connect(localhost,root,"");
mysql_select_db(oodb) or die( "Unable to select database");
$query = "SELECT id, tax,charges,datediff(curdate(),duedate) AS dayslate FROM oocust WHERE pd = ' '";
mysql_fetch_assoc(mysql_query($query));
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$amtdue = $row['amtdue'];
$shipamt = $row['shipamt'];
$charges = $row['charges'];
$tax = $charges * $taxrate;
$amtdue = $charges + $tax + $shipamt;
echo "tax is $tax <br /><br />";
$days_late = ($row['dayslate'] > 0)?$row['dayslate'] : 0;
$sql = "UPDATE oocust SET tax = " . $tax . ", amtdue = " . $amtdue . ", dayslate = " . $days_late . " WHERE
id='$id'";
mysql_query($sql) ;
$err=mysql_error();
if($err!="")
{
echo "Error in $sql: $err\n";
}
}
echo "Invoice Prep completed";
?>

 
You aren't retrieving the taxrate value from your database query, but rather from something that has been submitted by a form using the POST method.

Code:
$taxrate = [red]$_POST['taxrate'][/red]; 
echo "taxrate ".$data['taxrate'];

Assuming only one row is returned from your query, I think what you mean to do is:

Code:
$query = "SELECT id, tax,charges,datediff(curdate(),duedate) AS dayslate FROM oocust WHERE pd = ' '";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$taxrate=$row['taxrate'];

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
ok, the below code gets me the taxrate but I get this message?
"Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\invoice\invcalc.php on line 13"

<?php
mysql_connect("localhost", "root", "");
mysql_select_db(numbersdb) or die("Unable to select database");
$query = "SELECT taxrate FROM numbdata ";
$result = mysql_fetch_assoc(mysql_query($query));
$taxrate = $result['taxrate'];
echo "taxrate " . $taxrate;
$query = "SELECT id, tax,charges,datediff(curdate(),duedate) AS dayslate FROM oocust WHERE pd = ' '";
$stat = @mysql_fetch_assoc(mysql_query($query));
while ($row = mysql_fetch_array($result))
{
$id = $row['id'];
$amtdue = row['amtdue'];
$shipamt = $row['shipamt'];
$charges = $row['charges'];
$tax = $charges * $taxrate;
$amtdue = $charges + $tax + $shipamt;
echo "tax is $tax <br /><br />";
$days_late = ($row['dayslate'] > 0) ? $row['dayslate'] : 0;
$sql = "UPDATE oocust SET tax = " . $tax . ", amtdue = " . $amtdue . ", dayslate = " . $days_late . " WHERE id='$id'";
mysql_query($sql);
$err = mysql_error(); if ($err != "")
{
echo "Error in $sql: $err\n";
}
}
echo "Invoice Prep completed";
?>
 
So which one is line 13?

Look for a wrongly closed brace, or something else before that line that may be causing the following brace to be unexpected, like a missing ; or an unclosed quote or something like that.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Ooh good eye, totally missed that.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top