hello Can some one solve my bizzare code, I wrote code then I put a php code inside function variable, and in that function I adding again code inside php,
it means Script code in php code in script code..
var inputan = document.getElementById("inputan");
inputan.addEventListener('keydown', function() {
if (event.key === 'Enter') {
alert(inputan.value);
insertDB(inputan.value)
inputan.value = "";
}
});
function insertDB(inputan){
<?php
$Nama = ?> <script>inputan.value</script>;
<?php
if ( isset($Nama)) {
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "radian";
$Type = "test lagi";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Insert data into the table
$sql = "INSERT INTO `wew`(`Nama Product`, `Type`) VALUES ('$Nama','$Type')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
// Close connection
mysqli_close($conn);
// Output data in JSON format
echo json_encode(array('message' => 'Data inserted successfully'));
}
?>
}