I am building a web app and I have bumped into a roadblock that have been causing me trouble for a while.
The code I wrote is supposed to "INSERT/UPDATE" the chosen element value from the drop-down list to the RESPECTIVE $row['Visited']. I am confused at this point and i have tried using some javascript codes i got form google but nothing work. All i am getting is updated values only to the first row, eventhough i have selected the dropdown form from the second row. I have attached images of database
However, I am not getting the expected outcome so I must be doing something wrong so please, take a look at my code and tell me what can I do to achieve the desired result.
PHP/HTML
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "newtarget";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT *
FROM fos_data
WHERE Fos_Name='".$_GET["clientID"]."'
AND Route='".$_GET["fos_route"]."'" ;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<div class='form1'>
Buyer: ".$row['Buyer_Name']."<br />
Name: ".$row['Fos_Name']."<br />
Route: ".$row['Route']."<br />
Visited: ".$row['Visited']."
<form id='form'>
Have You Visited this Buyer Place?
<select id='mySelect'>
<option value='yes'>YES</option>
<option value='no'>NO</option>
</select>
<input type='submit'>
</form>
</div><br>";
}
}
else
{
echo "0 results";
}
$conn->close();
?>
SQL
-- phpMyAdmin SQL Dump
-- version 4.9.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: Mar 26, 2020 at 07:41 AM
-- Server version: 10.4.10-MariaDB
-- PHP Version: 5.6.40
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `newtarget`
--
-- --------------------------------------------------------
--
-- Table structure for table `fos_data`
--
DROP TABLE IF EXISTS `fos_data`;
CREATE TABLE IF NOT EXISTS `fos_data` (
`Buyer_Name` varchar(100) DEFAULT NULL,
`Fos_Name` varchar(100) DEFAULT NULL,
`Fos_Pass` double DEFAULT NULL,
`Fos_Phone` double DEFAULT NULL,
`Route` double DEFAULT NULL,
`Visited` varchar(100) DEFAULT NULL,
`Report` varchar(1000) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `fos_data`
--
INSERT INTO `fos_data` (`Buyer_Name`, `Fos_Name`, `Fos_Pass`, `Fos_Phone`, `Route`, `Visited`, `Report`) VALUES
('Buyer 1', 'Fos 1', 1, 1111, 1, '', ''),
('Buyer 2', 'Fos 1', 1, 1111, 1, '', ''),
('Buyer 3', 'Fos 1', 1, 1111, 1, '', ''),
('Buyer 4', 'Fos 1', 1, 1111, 2, '', ''),
('Buyer 5', 'Fos 1', 1, 1111, 2, '', ''),
('Buyer 6', 'Fos 1', 1, 1111, 2, '', ''),
('Buyer 7', 'Fos 1', 1, 1111, 3, '', ''),
('Buyer 8', 'Fos 1', 1, 1111, 3, '', ''),
('Buyer 9', 'Fos 1', 1, 1111, 3, '', ''),
('Buyer 10', 'Fos 1', 1, 1111, 3, '', ''),
('Buyer 11', 'Fos 2', 2, 2222, 1, '', ''),
('Buyer 12', 'Fos 2', 2, 2222, 1, '', ''),
('Buyer 13', 'Fos 2', 2, 2222, 1, '', ''),
('Buyer 14', 'Fos 2', 2, 2222, 2, '', ''),
('Buyer 15', 'Fos 2', 2, 2222, 2, '', ''),
('Buyer 16', 'Fos 2', 2, 2222, 2, '', ''),
('Buyer 17', 'Fos 2', 2, 2222, 2, '', ''),
('Buyer 18', 'Fos 2', 2, 2222, 3, '', ''),
('Buyer 19', 'Fos 2', 2, 2222, 3, '', ''),
('Buyer 20', 'Fos 2', 2, 2222, 3, '', '');
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Here are the image of what I want to achieve. MAIN PAGE IMAGE I appreciate your help, Thank you!