พอดีเป็นมือใหม่ อยากส่งค่าเป็น array (ก๊อปเขามามั่วๆ) แต่พอกด submit ไม่มีอะไรเกิดขึ้นเลยครับ ช่วยเหลือที TT
ไฟล์ profile.php
<script type='text/javascript'>
function addDrug(z) {
var x = document.getElementById('drug').rows[z.parentNode.rowIndex].cells.item(0).innerHTML;
var textbox = document.createElement("input");
textbox.name = "drug[]";
textbox.type = "text";
textbox.className = "form-control";
textbox.value = x;
document.getElementById('drug_text').innerHTML = "รหัสยา";
document.getElementById('drugSelected').appendChild(textbox);
}
function addAmount(){
var y = document.getElementById('amount').value;
var textbox2 = document.createElement("input");
textbox2.name = "amount2";
textbox2.type = "text";
textbox2.className = "form-control";
document.getElementById('amount_text').innerHTML = "จำนวน";
document.getElementById('drugAmount').appendChild(textbox2);
textbox2.value = y;
</script>
<form action="/cs/met/profile_met.php" method="post">
.
.
<div id="wow"class="col-10">
<div id="wow2" class="form-group row">
<span id="drugSelected" class="col-sm-6">
<label id="drug_text" ></label>
</span>
<span id="drugAmount" class="col-sm-6">
<label id="amount_text"></label>
</span>
</div>
</div>
.
.
<input type="submit" value="ยืนยัน">
</form>
ไฟล์ profile_met.php
<?php //พื้นที่สําหรับใส่สคริปต PHP ์
session_start();
require 'con1.php';
for($i =0;$i< count($_POST['drug']);$i++){
$sql3 = "SELECT * FROM drug WHERE drug_id ='".$_POST['drug'][$i]."'";
$res3 = mysqli_query($con,$sql3);
while ($row = mysqli_fetch_array($res3)) {
$check = $row['amount'];
$patient_id = $_POST['patient_id'];
if ($_POST['amount2']>$check) {
header( "Refresh:0.5; url= /cs/profile.php?patient_id=$patient_id", true, 303);
print "<script>alert('บันทึกข้อมูลล้มเหลว จำนวนยามีไม่พอ')</script>" ;
echo "$patient_id";
exit();
}
else {
$sql = "INSERT INTO history(his_id,patient_id,drug_id,sickness) values('NULL','".$_POST['patient_id']."','".$_POST['drug'[$i]]."'
,'".$_POST['sickness']."')";
$res = mysqli_query($con, $sql);
if($res){
$sql2 = "UPDATE drug SET amount = amount-'".$_POST['amount2']."' where drug_id ='".$_POST['drug'][$i]."'";
$res2 = mysqli_query($con,$sql2);
header("location:/cs/patient.php?patient_id = '".$_POST['patient_id']."'");
}
else{
header( "Refresh:0.5; url= /cs/profile.php?patient_id='".$_POST['patient_id']."'", true, 303);
print "<script>alert('กรุณากรอกข้อมูลให้ครบถ้วน')</script>" ;
}
}
}
}
mysqli_close($con);
?>
ช่วยดูโค้ดให้ทีครับ กด Submit แล้วไม่เกิดอะไรขึ้นเลย
ไฟล์ profile.php
<script type='text/javascript'>
function addDrug(z) {
var x = document.getElementById('drug').rows[z.parentNode.rowIndex].cells.item(0).innerHTML;
var textbox = document.createElement("input");
textbox.name = "drug[]";
textbox.type = "text";
textbox.className = "form-control";
textbox.value = x;
document.getElementById('drug_text').innerHTML = "รหัสยา";
document.getElementById('drugSelected').appendChild(textbox);
}
function addAmount(){
var y = document.getElementById('amount').value;
var textbox2 = document.createElement("input");
textbox2.name = "amount2";
textbox2.type = "text";
textbox2.className = "form-control";
document.getElementById('amount_text').innerHTML = "จำนวน";
document.getElementById('drugAmount').appendChild(textbox2);
textbox2.value = y;
</script>
<form action="/cs/met/profile_met.php" method="post">
.
.
<div id="wow"class="col-10">
<div id="wow2" class="form-group row">
<span id="drugSelected" class="col-sm-6">
<label id="drug_text" ></label>
</span>
<span id="drugAmount" class="col-sm-6">
<label id="amount_text"></label>
</span>
</div>
</div>
.
.
<input type="submit" value="ยืนยัน">
</form>
ไฟล์ profile_met.php
<?php //พื้นที่สําหรับใส่สคริปต PHP ์
session_start();
require 'con1.php';
for($i =0;$i< count($_POST['drug']);$i++){
$sql3 = "SELECT * FROM drug WHERE drug_id ='".$_POST['drug'][$i]."'";
$res3 = mysqli_query($con,$sql3);
while ($row = mysqli_fetch_array($res3)) {
$check = $row['amount'];
$patient_id = $_POST['patient_id'];
if ($_POST['amount2']>$check) {
header( "Refresh:0.5; url= /cs/profile.php?patient_id=$patient_id", true, 303);
print "<script>alert('บันทึกข้อมูลล้มเหลว จำนวนยามีไม่พอ')</script>" ;
echo "$patient_id";
exit();
}
else {
$sql = "INSERT INTO history(his_id,patient_id,drug_id,sickness) values('NULL','".$_POST['patient_id']."','".$_POST['drug'[$i]]."'
,'".$_POST['sickness']."')";
$res = mysqli_query($con, $sql);
if($res){
$sql2 = "UPDATE drug SET amount = amount-'".$_POST['amount2']."' where drug_id ='".$_POST['drug'][$i]."'";
$res2 = mysqli_query($con,$sql2);
header("location:/cs/patient.php?patient_id = '".$_POST['patient_id']."'");
}
else{
header( "Refresh:0.5; url= /cs/profile.php?patient_id='".$_POST['patient_id']."'", true, 303);
print "<script>alert('กรุณากรอกข้อมูลให้ครบถ้วน')</script>" ;
}
}
}
}
mysqli_close($con);
?>