在this question asked and fixed earlier today之后,我继续使用PHP代码的第二部分if($payment_type == "installment")
。
在这部分中,我需要将最后插入的ID放入表patient_info
并将debt
表添加为info_id
。债务表的作用是将每个project
设置的分期付款信息保存为installment
。
现在的代码是:
if($payment_type == "installment")
{
try
{
//Insert into patient Info
$sqlInfo = "INSERT INTO patient_info(id_logged, patient_id, insurrance_type, project, project_cost,
payment_type, prescription, date_now, time_now, ext, do, endo, fm, crown, rmvbl, paro)
VALUES(:id_logged, :patient_id, :ins, :proj_d, :project_c, :payment_type, :presc,
:date_p, now(), :e, :d, :en, :f, :c, :r, :p)";
$sqlInfoStmt = $conn->prepare($sqlInfo);
$sqlInfoStmt->bindValue(":id_logged", $id_logged);
$sqlInfoStmt->bindValue(":patient_id", $patient_id);
$sqlInfoStmt->bindValue(":ins", $ins);
$sqlInfoStmt->bindValue(":proj_d", $proj_d);
$sqlInfoStmt->bindValue(":project_c", $project_c);
$sqlInfoStmt->bindValue(":payment_type", $payment_type);
$sqlInfoStmt->bindValue(":presc", $presc);
$sqlInfoStmt->bindValue(":date_p", $date_p);
$sqlInfoStmt->bindValue(":e", $e);
$sqlInfoStmt->bindValue(":d", $d);
$sqlInfoStmt->bindValue(":en", $en);
$sqlInfoStmt->bindValue(":f", $f);
$sqlInfoStmt->bindValue(":c", $c);
$sqlInfoStmt->bindValue(":r", $r);
$sqlInfoStmt->bindValue(":p", $p);
$sqlInfoStmt->execute();
//get the project info id
$lastId = $conn->lastInsertId();
//Insert into teeth table
$sqlTeeth = "INSERT INTO teeth (id_logged, patient_id, one, two, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eightteen, nineteen, twenty, twone, twtwo, twthree, twfour, twfive, twsix, twseven, tweight, twnine, thirty, thone, thtwo, date_now) VALUES (:id_logged, :patient_id, :one, :two, :three, :four, :five, :six, :seven, :eight, :nine, :ten, :eleven, :twelve, :thirteen,
:fourteen, :fifteen, :sixteen, :lone, :ltwo, :lthree, :lfour, :lfive, :lsix, :lseven, :leight, :lnine, :lten, :leleven, :ltwelve, :lthirteen,
:lfourteen, :lfifteen, :lsixteen)";
$sqlTeethStmt = $conn->prepare($sqlTeeth);
$sqlTeethStmt->bindValue(":id_logged", $id_logged);
$sqlTeethStmt->bindValue(":patient_id", $patient_id);
$sqlTeethStmt->bindValue(":one", $one);
$sqlTeethStmt->bindValue(":two", $two);
$sqlTeethStmt->bindValue(":three", $three);
$sqlTeethStmt->bindValue(":four", $four);
$sqlTeethStmt->bindValue(":five", $five);
$sqlTeethStmt->bindValue(":six", $six);
$sqlTeethStmt->bindValue(":seven", $seven);
$sqlTeethStmt->bindValue(":eight", $eight);
$sqlTeethStmt->bindValue(":nine", $nine);
$sqlTeethStmt->bindValue(":ten", $ten);
$sqlTeethStmt->bindValue(":eleven", $eleven);
$sqlTeethStmt->bindValue(":twelve", $twelve);
$sqlTeethStmt->bindValue(":thirteen", $thirteen);
$sqlTeethStmt->bindValue(":fourteen", $fourteen);
$sqlTeethStmt->bindValue(":fifteen", $fifteen);
$sqlTeethStmt->bindValue(":sixteen", $sixteen);
$sqlTeethStmt->bindValue(":lone", $lone);
$sqlTeethStmt->bindValue(":ltwo", $ltwo);
$sqlTeethStmt->bindValue(":lthree", $lthree);
$sqlTeethStmt->bindValue(":lfour", $lfour);
$sqlTeethStmt->bindValue(":lfive", $lfive);
$sqlTeethStmt->bindValue(":lsix", $lsix);
$sqlTeethStmt->bindValue(":lseven", $lseven);
$sqlTeethStmt->bindValue(":leight", $leight);
$sqlTeethStmt->bindValue(":lnine", $lnine);
$sqlTeethStmt->bindValue(":lten", $lten);
$sqlTeethStmt->bindValue(":leleven", $leleven);
$sqlTeethStmt->bindValue(":ltwelve", $ltwelve);
$sqlTeethStmt->bindValue(":lthirteen", $lthirteen);
$sqlTeethStmt->bindValue(":lfourteen", $lfourteen);
$sqlTeethStmt->bindValue(":lfifteen", $lfifteen);
$sqlTeethStmt->bindValue(":lsixteen", $lsixteen);
$sqlTeethStmt->execute();
try
{
//Add to debt table
$sqlDebt = "INSERT INTO debt(info_id, id_logged, patient_id, payment, date_now, time_now)
VALUES(:info_id, :id_logged, :patient_id, :payment, :date_now, now())";
$sqlDebtStmt = $conn->prepare($sqlDebt);
$sqlDebtStmt->bindValue(":info_id", $lastId);
$sqlDebtStmt->bindValue(":id_logged", $id_logged);
$sqlDebtStmt->bindValue(":patient_id", $patient_id);
$sqlDebtStmt->bindValue(":payment", $fp);
$sqlDebtStmt->bindValue(":date_now", $date_p);
$sqlDebtStmt->execute();
echo "added";
}
catch(PDOException $msg)
{
echo $msg->getMessage();
//echo "not added";
}
}
catch(PDOException $msg)
{
echo $msg->getMessage();
//echo "not added";
}
}
我没有更改AJAX脚本中的任何内容,当我选择类型installment
时,数据已正确添加to patient_info
和teeth
,但未添加到debt table
。我在XHR或控制台中看不到任何日志错误。
FORM
<form>
<div class="box-body" id="toggleDiv">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label style="float:left">Starting date</label>
<input type="date" class="form-control" id="date_now" name="date_now"/>
<label style="float:left">Project Description</label>
<input type="text" class="form-control" id="project_desc" name="project_desc"/>
<label style="float:left">Project Cost</label>
<input type="text" class="form-control" id="project_cost" name="project_cost"/>
<label style="float:left">Payment Type</label>
<select class="form-control select2" id="pay_type" name="pay_type">
<option value="0">Choose</option>
<option value="cash">Cash</option>
<option value="installment">Installment</option>
</select>
<label style="float:left;">First Payment (In case of installment)</label>
<input type="text" class="form-control" id="first_pay" name="first_pay"/>
<label style="float:left">Date of Payment</label>
<input type="date" class="form-control" id="date_pay" name="date_pay"/>
</div><!-- /.form-group -->
</div><!-- /.col -->
<div class="col-md-6">
<div class="form-group">
<label style="float:left">Inssurance Type (Gov, Social, ...)</label>
<input type="text" class="form-control" id="inssurance" name="inssurance"/>
<label style="float:left">Prescription</label>
<input type="text" class="form-control" id="prescription" name="prescription"/>
<div class="box box-danger">
<div class="box-body">
<!-- Date dd/mm/yyyy -->
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-check"></i>
</div>
<input type="text" class="form-control" id="ext" name="ext" placeholder="ext"/>
<input type="text" class="form-control" id="do" name="do" placeholder="do"/>
<input type="text" class="form-control" id="endo" name="endo" placeholder="endo"/>
<input type="text" class="form-control" id="fm" name="fm" placeholder="fm"/>
<input type="text" class="form-control" id="crown" name="crown" placeholder="crown"/>
<input type="text" class="form-control" id="rmvbl" name="rmvbl" placeholder="rmvbl"/>
<input type="text" class="form-control" id="paro" name="paro" placeholder="paro"/>
</div><!-- /.input group -->
</div><!-- /.form group -->
</div>
</div>
</div><!-- /.form-group -->
<div class="form-group">
</div><!-- /.form-group -->
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.box-body -->
<div class="row">
<div class="col-md-6">
<div class="box box-danger">
<div class="box-header">
<h3 class="box-title">Upper Jaw</h3>
</div>
<div class="box-body">
<!-- IP mask -->
<div class="form-group col-md-6">
<label>Upper Right Teeth</label>
<div class="input-group">
<div class="input-group-addon">
<i><img src="../images/molar.png" style="width:15px; height:15px"/>Upper Right</i>
</div>
<input type="text" class="form-control" id="one" name="one" placeholder="3rd Molar"/>
<input type="text" class="form-control" id="two" name="two" placeholder="2nd Molar"/>
<input type="text" class="form-control" id="three" name="three" placeholder="1st Molar"/>
<input type="text" class="form-control" id="four" name="four" placeholder="2nd Bicuspid"/>
<input type="text" class="form-control" id="five" name="five" placeholder="1st Bicuspid"/>
<input type="text" class="form-control" id="six" name="six" placeholder="cuspid"/>
<input type="text" class="form-control" id="seven" name="seven" placeholder="lateral"/>
<input type="text" class="form-control" id="eight" name="eight" placeholder="central"/>
</div><!-- /.input group -->
</div><!-- /.form group -->
<div class="form-group col-md-6">
<label>Upper Left Teeth</label>
<div class="input-group">
<input type="text" class="form-control" id="nine" name="nine" placeholder="3rd Molar"/>
<input type="text" class="form-control" id="ten" name="ten" placeholder="2nd Molar"/>
<input type="text" class="form-control" id="eleven" name="eleven" placeholder="1st Molar"/>
<input type="text" class="form-control" id="twelve" name="twelve" placeholder="2nd Bicuspid"/>
<input type="text" class="form-control" id="thirteen" name="thirteen" placeholder="1st Bicuspid"/>
<input type="text" class="form-control" id="fourteen" name="fourteen" placeholder="cuspid"/>
<input type="text" class="form-control" id="fifteen" name="fifteen" placeholder="lateral"/>
<input type="text" class="form-control" id="sixteen" name="sixteen" placeholder="central"/>
<div class="input-group-addon">
<i><img src="../images/molar.png" style="width:15px; height:15px"/>Upper Left</i>
</div>
</div><!-- /.input group -->
</div><!-- /.form group -->
</div><!-- /.box-body -->
</div><!-- /.box -->
</div><!-- /.col (left) -->
<div class="col-md-6">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Lower Jaw</h3>
</div>
<div class="box-body">
<!-- IP mask -->
<div class="form-group col-md-6">
<label>Lower Right Teeth</label>
<div class="input-group">
<div class="input-group-addon">
<i><img src="../images/molar.png" style="width:15px; height:15px"/>Lower Right</i>
</div>
<input type="text" class="form-control" id="lone" name="lone" placeholder="3rd Molar"/>
<input type="text" class="form-control" id="ltwo" name="ltwo" placeholder="2nd Molar"/>
<input type="text" class="form-control" id="lthree" name="lthree" placeholder="1st Molar"/>
<input type="text" class="form-control" id="lfour" name="lfour" placeholder="2nd Bicuspid"/>
<input type="text" class="form-control" id="lfive" name="lfive" placeholder="1st Bicuspid"/>
<input type="text" class="form-control" id="lsix" name="lsix" placeholder="cuspid"/>
<input type="text" class="form-control" id="lseven" name="lseven" placeholder="lateral"/>
<input type="text" class="form-control" id="leight" name="leight" placeholder="central"/>
</div><!-- /.input group -->
</div><!-- /.form group -->
<div class="form-group col-md-6">
<label>Lower Left Teeth</label>
<div class="input-group">
<input type="text" class="form-control" id="lnine" name="lnine" placeholder="3rd Molar"/>
<input type="text" class="form-control" id="lten" name="lten" placeholder="2nd Molar"/>
<input type="text" class="form-control" id="leleven" name="leleven" placeholder="1st Molar"/>
<input type="text" class="form-control" id="ltwelve" name="ltwelve" placeholder="2nd Bicuspid"/>
<input type="text" class="form-control" id="lthirteen" name="lthirteen" placeholder="1st Bicuspid"/>
<input type="text" class="form-control" id="lfourteen" name="lfourteen" placeholder="cuspid"/>
<input type="text" class="form-control" id="lfifteen" name="lfifteen" placeholder="lateral"/>
<input type="text" class="form-control" id="lsixteen" name="lsixteen" placeholder="central"/>
<div class="input-group-addon">
<i><img src="../images/molar.png" style="width:15px; height:15px"/>Lower Left</i>
</div>
</div><!-- /.input group -->
</div><!-- /.form group -->
</div><!-- /.box-body -->
</div><!-- /.box -->
<button type="button" class="btn btn-danger" id="add_project">Add</button>
<!-- iCheck -->
</div><!-- /.col (right) -->
</div><!-- /.row -->
</form>
答案 0 :(得分:0)
代码中的问题是您处理已声明变量$ lastId
值的数据的方式$lastId = $conn->lastInsertId();
你再次使用相同的债券表变量显然会与设置和存储变量的值冲突
尝试将债务表中的值更改为其他内容,例如将其重命名为$ lastIddebt
这应该可行。