Hi Sir by using your code and guidance i try to implement this in following steps
- get form value via Post (city value which i get is 1)
2)look at mysql table which have two fields id, city - sql querry to get database table city value (which is London) in which city from post will be equal to id field of the database (all working fine)
3- I wanted to replace 1 with london. - but when used replace value as then its given just “L” rather than full London as city and if I posted two values from Html form then “O” is displaying for 2nd line rather than value of 2nd row
echo '<td style = "text-align:left; border:1px solid #cccccc;">'.$city1[$i].'</td>';
Below is full code
<?php
if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit']))
{
// getting all values from the HTML form
$country = $_POST['country'];
$state = $_POST['state'];
$city = $_POST['city'];
// database details
$host = "localhost";
$username = "thehospi_root";
$password = "u1m1a1r1";
$dbname = "thehospi_hmis2";
// creating a connection
$con = mysqli_connect($host, $username, $password, $dbname);
// to ensure that the connection is made
if (!$con)
{
die("Connection failed!" . mysqli_connect_error());
foreach($_POST['city'] as $k => $v){
$city = $_POST['city'][$k];
$sql = "SELECT `city` FROM `city` WHERE `id` = '$city'";
$result = $con->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$city1 = $row['city'];
echo var_dump($city1); // for checking value is given after check found
}}
}
?>
//Now belonw I want to display value
<html>
<head>
<link rel="stylesheet" type="text/css" href="style1.css" />
</head>
<body>
for ($i=0;$i<count($_POST['country']);$i++) {
echo "<tr>";
echo '<td style = "text-align:left; border:1px solid #cccccc;">'.$_POST['country'][$i].'</td>';
echo '<td style = "text-align:left; border:1px solid #cccccc;">'.$city1[$i].'</td>';
}
?>
</table>