PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old August 30th, 2004, 02:13 PM
par par is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 par User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
insert then update

Hello,

I am getting an error on my update statement."Invalid query: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1". I am pretty new to PHP and MYSQL and not sure what the problem is. Any help would be great.
Regards
Paul
Here is the entire code:
<?php
// create short variable names

$link = mysql_connect("$server","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database",$link) or die ("Unable to select requested database.");
$result = mysql_query("SELECT MAX(KeyID) FROM fuellog");
$row = mysql_fetch_array($result);
$keyid = $row[0]+1;
$app = mysql_query("SELECT station, meter, estmeter, meter2, estmeter FROM apparatus WHERE keyid=$apparatus");
$station1 = mysql_fetch_array($app);
$resultstation =$station1[0];
$meter = $station1[1];
$estmeter = $station[2];
$meter2 = $station[3];
$estmeter2 = $station[4];
$diffmeter = $meterreading-$meter;
$diffestmeter = $meterreading-$estmeter;
$diffmeter2 = $hourreading-$meter2;
$diffestmeter2= $hourreading-$estmeter2;
$mpg = $diffmeter/$numberofgallons;
$date=time();
$timestamp=date('YmdHis0000',$date);
$dat=date('Ymd',$date);
$totalcost=$costpergallon * $numberofgallons;
$holdmeter=round($METER,1);
// insert new record
$query = "insert into fuellog(timestamp,keyid,apparatus,apparatusr,emplo yee,employeer,station,stationr,meter,meter2,date,v endor,vendorr,fueltype,fueltyper,quantity,cpu,capa city,grandcost,totcost,disttrav,disttrav2,mangpart ,part,mpg)
values ('$timestamp','$keyid','$apparatus','apparatus','$ empno','employee','$resultsstation','station','$me terreading','$hourreading','$dat',149,'vendor',$fu eltype,'fueltype','$numberofgallons','$costpergall on',0,'$totalcost','$totalcost','$diffmeter','$dif fmeter2',0,0,$mpg)";
$result = mysql_query($query);
$sql="UPDATE apparatus SET meter='$meterreading' WHERE keyid=$appartatus";
$res = mysql_query($sql);
// display what was entered by user
echo '<br/>';
echo '<b>Request Date:</b>'.date('m-d-Y',$date).'<br/>';
echo '<br/>';
echo '<b>meter:</b>'.$meterreading.'<br/>';
echo '<br/>';
echo 'Your Fuel log has been saved to the database.<br/>';
echo '<br/>';
echo 'Please Click home to take you back to RFD home page';
echo '<br/>';

if (!$result){
die('Invalid query: ' . mysql_error());
}
if (!$res){
die('Invalid query: ' . mysql_error());
}
// Close the connection
mysql_close($link);
?>

Reply With Quote
  #2  
Old August 31st, 2004, 02:49 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
Several points for you to consider and try -

1) Why do you need to insert it then update it, couldn't you just build a different insert query and halve the work done with the db?

2) To help you narrow down which statement is causing the problem, comment out the second one and run it. That way you can tell which one is causing you trouble but bare in mind if the first causes an error the second may also but is never being reached.

3) Where you have SET meter='$meterreading' this could be causing an error if $meterreading is infact a number since you won't want the 's around it.

Hope some of this helps,

-KM-

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > insert then update


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway