php - Store 2 inputs having same name into 1 'address' column of the database -
i have 2 address inputs 'address1'
, 'address2'
having same name 'address[]' . want put value of both inputs in single address column of database problem data of 2nd input being stored database.
index.php
$addressdata = $_post['address']; foreach ($addressdata $addressvalue) { $query = "insert `users` (`name` ,`address` , `birthdate` ,`age` , `coach` , `phone`,`email` ,`password`) values ( '".mysqli_real_escape_string($link, $_post['name'])."' , '".mysqli_real_escape_string($link, $addressvalue)."' ,'".mysqli_real_escape_string($link, $_post['birthdate'])."' ,'".mysqli_real_escape_string($link, $_post['age'])."' , '".mysqli_real_escape_string($link, $_post['coach'])."' , '".mysqli_real_escape_string($link, $_post['phone'])."' , '".mysqli_real_escape_string($link, $_post['email'])."' , '".mysqli_real_escape_string($link, $_post['password'])."')"; }
<div class="form-group row"> <label class="col-sm-2 form-control-label">address1</label> <div class="col-sm-10"> <input type="text" id="address" class="form-control" name="address[]" placeholder="home address"> <span class="fa fa-map-marker"></span> </div> </div> <div class="form-group row"> <label class="col-sm-2 form-control-label">address2</label> <div class="col-sm-10"> <input type="text" id="address2" class="form-control" name="address[]" placeholder="city,pincode...."> <span class="fa fa-map-marker"></span> </div> </div>
it because insert inside foreach loop. if want address saved on single table, might want combine address first , insert outside foreach loop. see updated code below
$addressdata = $_post['address']; $address = ""; foreach ($addressdata $addressvalue) { $address .= "\n" . $addressvalue; } $query = "insert `users` (`name` ,`address` , `birthdate` ,`age` , `coach` , `phone`,`email` ,`password`) values ( '".mysqli_real_escape_string($link, $_post['name'])."' , '".mysqli_real_escape_string($link, $address)."' , '".mysqli_real_escape_string($link, $_post['birthdate'])."' , '".mysqli_real_escape_string($link, $_post['age'])."' , '".mysqli_real_escape_string($link, $_post['coach'])."' , '".mysqli_real_escape_string($link, $_post['phone'])."' , '".mysqli_real_escape_string($link, $_post['email'])."' , '".mysqli_real_escape_string($link, $_post['password'])."' )";
Comments
Post a Comment