当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Insert into one table then update another

问题描述:

Hi People I'm looking to insert into one table then pass other information to update another.

I'm currently using an ajax command to do this:

$.ajax({

type: "POST",

url: "syncdata.php",

data: {depot: json, techname: techsname}})

.done(function(data){

//do something

})

.fail(function(){

alert("Something went wrong.<br>ER: SY01");

});

My data - depot is an object that does not contain the techname.

The depot information gets stored within a table called "depotreport".

The techname includes just the usersID number which i wish to store within another table called jobs.

syncdata.php

$sql = "INSERT INTO

depotreport (JobID, SiteID, VisitDate, AirPress, LELMeth, VolMeth, PPMMeth, LELProp, VolProp, VisitType, ConditionPipes, SignOp, SignSpar, SignReg, SignCylin, CheckWorking, CheckFilter, CheckoRing, CheckGNozzle, CheckRBlock, CheckSAlign, CheckMSwitch, CheckLED, RepFilter, RepBlock, CheckSolenoid, CheckSoRing, CheckHW, CheckDValue, CheckPCB, RepDisk, CheckDisk, CheckDT40, Working, GascoNo, TestDepot, DepotSat, TestGMI, GMISat, DepotDisk, PrintDepot, PrintGMI, TestInst, AuditInst, PPMInst, TestReason, AuditReason, PPMReason, AuditComplete)

VALUES

('$ID[$i]', '$SiteID[$i]', '$visitDate[$i]', '$numAirP[$i]', '$numLelM[$i]', '$numAVolM[$i]', '$numPpmM[$i]', '$numLelP[$i]', '$numVolP[$i]', 'this', '$flpHoses[$i]', '$flpOperating[$i]', '$flpSpares[$i]', '$flpRegs[$i]', '$flpCylC[$i]', '$flpWorking[$i]', '$flpFcleaned[$i]', '$flpOring[$i]', '$flpCgas[$i]', '$flpRblock[$i]', '$flpSensor[$i]', '$flpMicroswitch[$i]', '$flpLed[$i]', '$flpFchanged[$i]', '$flpBrenew[$i]', '$flpSvalves[$i]', '$flpSoRings[$i]', '$flpHWtest[$i]', '$flpTestD[$i]', '$flpPCB[$i]', '$flpDhead[$i]', '$flpDchanged[$i]', '$flpDT40[$i]', '$flpWorkingDe[$i]', '$numGasCo[$i]', '$datetDepot[$i]', '$flpDSatisfactory[$i]', '$datetGmi[$i]', '$flpGSatisfactory[$i]', '$dateDdisk[$i]', '$flpPrintoutD[$i]', '$flpPrintoutG[$i]', '$numTestIns[$i]', '$numAuditIns[$i]', '$numPpmIns[$i]', '$flpTCall[$i]', '$flpACall[$i]', '$flpPCall[$i]', '$dateAuditC[$i]');

UPDATE

jobs (CompletedBy)

SET

('$tech')

WHERE JobID = '$ID[$i]'";

if (!mysqli_query($con,$sql)){

die('Error: ' . mysqli_error($con));

}

else{

$synctotal++;

}

I've had a look around and found out that if i use a semicolon between my insert and my update it should work, this is not the case. I have also looked a triggers but i cannot do it that way because my depotreport does not contain anything to do with my techname.

Could someone please enlighten me to the answer. Thanks.

分享给朋友:
您可能感兴趣的文章:
随机阅读: