I am trying to insert data into phpMyAdmin using jQuery and User Agent Switcher for Chrome. I modified the code given in this example: https://www.w3schools.com/php/php_mysql_insert.asp
This data is imported into the database, When I open the file (index.php).
index.php
<script type="text/javascript">
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
$('body').addClass('mobile');
<?php
$db = mysqli_connect(localhost,root,root,hospital) or die ("Opps, Some thing went wrong!");
$today = date('Y-m-d');
mysqli_query($db,"INSERT INTO `view` (`id`, `date`, `device`) VALUES (NULL, '$today', 'mobile' )" );
?>
} else {
<?php
$today = date('Y-m-d');
mysqli_query($db,"INSERT INTO `view` (`id`, `date`, `device`) VALUES (NULL, '$today', 'desktop' )" );
?>
}
</script>
phpMyAdmin
----------------------------
|id | date | device |
----------------------------
|1 | 2020-01-15 | mobile |
|2 | 2020-01-15 | desktop |
----------------------------
This data is sent incorrectly to the phpMyAdmin. It imports both devices (mobile and desktop) into the phpMyAdmin and What code do you recommend to output one device the same code above?