|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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); ?> |
|
#2
|
|||
|
|||
|
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- |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > insert then update |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|