How to update multiple rows php -
i want update multiple rows
this html code :
<form action="" method="post"> <input type="text" name="name" placeholder=""/> <input type="text" name="phone" placeholder=""/> <input type="text" name="blood" placeholder=""/> <input type="text" name="id" placeholder=""/> <input type="text" name="email" placeholder=""/> <input type="submit" name="sub" value=""/> </form> and php code :
if(isset($_post['sub'])) { $name = $_post['name']; $phone = $_post['phone']; $blood = $_post['blood']; $id = $_post['id']; $email = $_post['email']; if($name or $phone or $blood or $id or $email) { $res_11 = mysql_query("update `general_info` set `name`='$name',`phone`='$phone',`blood`='$blood',`id_2`='$id',`email`='$email' `id`='1'") or die(mysql_error()); } }else{ echo "error"; } i have table this
name | phone | blood and want if body update 1 row update
if write new phone update phone in database
try code:
if(isset($_post['sub'])) { $subquery = ""; if(isset($_post['name']) && $_post['name'] != "") { $subquery .= " name = '". $_post['name'] ."',"; $name = $_post['name']; } if(isset($_post['phone']) && $_post['phone'] != "") { $subquery .= " phone = '". $_post['phone'] ."',"; $phone = $_post['phone']; } if(isset($_post['blood']) && $_post['blood'] != "") { $subquery .= " blood = ". $_post['blood'] .","; $blood = $_post['blood']; } if(isset($_post['email']) && $_post['email'] != "") { $subquery .= " email= '". $_post['email'] ."',"; $email = $_post['email']; } if(isset($_post['id']) && $_post['id'] != "") { $subquery .= " id_2 = '". $_post['id'] ."',"; $id = $_post['id']; } if($name or $phone or $blood or $id or $email) { $res_11 = mysql_query("update `general_info` set ". substr($subquery, 0, -1) ." `id`='1'") or die(mysql_error()); } }else{ echo "error"; }
Comments
Post a Comment