setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } if ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST['name'] && $_POST['pass'] && $_POST['email']) { $mysqli = new mysqli($mariaServer, $mariaUser, $mariaPass, $mariaDb); if ($mysqli->connect_error) die("Connection failed: " . $mysqli->connect_error); $result = $mysqli->query("SELECT bv FROM business_verticals"); if ($result) { $access_array = array(); while ($row = $result->fetch_assoc()) { $access_array[] = $row['bv']; } // $access_array = ['beanstalk', 'inhouse', 'teenybeans', 'iimtt', 'buzzapp', 'atheneum', 'teenybeans_curriculum']; $access_values_array = []; foreach ($access_array as $access) { if (isset($_POST[$access])) { $access_values_array[] = $_POST[$access]; } } $selected_access = implode(',', $access_values_array); $result->free(); // print_r($access_array); } else { echo "Error: " . $mysqli->error; } $mysqli->close(); $apiUrl = 'https://api.siliconpin.com/v3/list/country/state/?country=IN'; $handle = fopen($apiUrl, 'rb'); if ($handle === false) { echo 'Unable to open URL'; } else { $jsonResponse = stream_get_contents($handle); fclose($handle); $states = json_decode($jsonResponse, true); if ($states === null) { echo 'Error decoding JSON from API'; } else { $state_values_array = []; if (isset($_POST['international'])) $state_values_array[] ='international'; foreach ($states as $state) { if (isset($_POST[$state['iso2']])) $state_values_array[] = $_POST[$state['iso2']]; } $selected_states = implode(',', $state_values_array); } } try { $pass=md5($_POST['pass']); $stmt = $conn->prepare("INSERT INTO users (name, email, mobile, access, pass, states) VALUES (:name, :email, :mobile, :access, :pass, :states)"); $stmt->bindParam(':name', $_POST['name']); $stmt->bindParam(':email', $_POST['email']); $stmt->bindParam(':mobile', $_POST['phone']); $stmt->bindParam(':access', $selected_access); $stmt->bindParam(':pass', $pass); $stmt->bindParam(':states', $selected_states); // Bind selected states $stmt->execute(); echo "A new user added."; } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } } ?>
| Name | Mobile | Time | Access | Access by State | Action | |
|---|---|---|---|---|---|---|