php - How to update 3 tables columns while only one column is visible to the page -
this table column display message depends on user preferred language choice in db. eg if preferred language eng eng message show ps: in database, there's 3 column storing 3 types of message of different languages
<?php $possiblelang = ["繁體","简体","eng"]; $testareafield = ["traditionalmessage","simplifiedmessage","engmessage"]; $treatmentname = ["vaccinename1","vaccinename2","vaccinename3"]; $treatmentnamesuffix = ["\n下一個注射期為:","\n下一个注射期为:","\nnext injection period be:"]; $index = array_search($row['language'],$possiblelang); ?> <td> <textarea rows="3" cols="18" class="url" name="<?php echo $testareafield[$index]; ?>[]" data-value="<?php echo $row[$treatmentname[$index]] . $treatmentnamesuffix[$index]; ?>"><?php echo $row[$testareafield[$index]]; ?> </textarea> </td>
this table @ edit page displays data db , updates data db.
if (isset($_post['submit'])){ foreach ($_post['patientid'] $index => $patientid) { $id = mysql_real_escape_string($_post['id'][$index]); $data1 = mysql_real_escape_string($patientid); $data17 = mysql_real_escape_string($_post['patienthkid'][$index]); $data2 = mysql_real_escape_string($_post['vaccineid'][$index]); $data5 = mysql_real_escape_string($_post['vaccinename3'][$index]); $data6 = mysql_real_escape_string($_post['totalnoofinjection'][$index]); $data7 = mysql_real_escape_string($_post['nthinjection'][$index]); $data8 = mysql_real_escape_string($_post['date'][$index]); $data9 = mysql_real_escape_string($_post['nextdate'][$index]); $data10 = mysql_real_escape_string($_post['skip'][$index]); $data11 = mysql_real_escape_string($_post['language'][$index]); $data12 = mysql_real_escape_string($_post['traditionalmessage'][$index]); $data13 = mysql_real_escape_string($_post['simplifiedmessage'][$index]); $data14 = mysql_real_escape_string($_post['engmessage'][$index]); $data15 = mysql_real_escape_string($_post['status'][$index]); $data16 = mysql_real_escape_string($_post['nurse'][$index]); if ($data12 != null) { mysql_query("update patientvaccinedetail set patientid ='$data1',patienthkid ='$data17',vaccineid='$data2',vaccinename3='$data5', totalnoofinjection='$data6',nthinjection='$data7', date='$data8',nextdate='$data9',skip='$data10',language='$data11', traditionalmessage='$data12',status='$data15',nurse='$data16' id=$id") or die(mysql_error()); } else if ($data13 != null) { mysql_query("update patientvaccinedetail set patientid ='$data1',patienthkid ='$data17',vaccineid='$data2',vaccinename3='$data5', totalnoofinjection='$data6', nthinjection='$data7',date='$data8',nextdate='$data9', skip='$data10',language='$data11', simplifiedmessage='$data13',status='$data15',nurse='$data16' id=$id") or die(mysql_error()); } else if ($data14 != null) { mysql_query("update patientvaccinedetail set patientid ='$data1',patienthkid ='$data17',vaccineid='$data2', vaccinename3='$data5', totalnoofinjection='$data6', nthinjection='$data7',date='$data8',nextdate='$data9', skip='$data10',language='$data11', engmessage='$data14',status='$data15',nurse='$data16' id=$id") or die(mysql_error()); } } }
the issues whenever click save , only one
column of message saved, other 2 column updated null in database. desired outcome update both 3 columns while 1 column visible page. idea. in advance
do not update columns not being targeted update. example, if traditional message selected, update column. use separate queries here.
foreach ($_post['patientid'] $index => $patientid) { $id = mysql_real_escape_string($_post['id'][$index]); $data1 = mysql_real_escape_string($patientid); $data2 = mysql_real_escape_string($_post['traditionalmessage'][$index]); $data3 = mysql_real_escape_string($_post['simplifiedmessage'][$index]); $data4 = mysql_real_escape_string($_post['engmessage'][$index]); if ($data2 != null && $data2 != '') { mysql_query("update table set patientid ='$data1', traditionalmessage='$data2' id=$id") or die(mysql_error()); } else if ($data3 != null && $data3 != '') { mysql_query("update table set patientid ='$data1', simplifiedmessage='$data3' id=$id") or die(mysql_error()); } else if ($data4 != null && $data4 != '') { mysql_query("update table set patientid ='$data1', engmessage='$data4' id=$id") or die(mysql_error()); } }
note believe using old , deprecated php api mysql. starters, benefit lot using prepared statements.
Comments
Post a Comment