Add exams from exam156 to exam199

This commit is contained in:
2024-05-16 10:51:54 +02:00
parent 19bf1b8ac8
commit 959a167e9d
29 changed files with 635 additions and 0 deletions

41
exam180/index.php Normal file
View File

@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
function insert(){
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
document.getElementById('message').innerHTML = xmlhttp.responseText;
}
}
parameters = 'text=' + document.getElementById('text').value;
xmlhttp.open('POST', 'update.inc.php', true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); // slicno kao header() u php- u
xmlhttp.send(parameters);
}
</script>
</head>
<body>
Insert data: <input type="text" id="text">
<input type="button" value="Submit" onclick="insert();">
<div id="message"></div>
</body>
</html>

25
exam180/update.inc.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
if (isset($_POST['text'])) {
$text = $_POST['text'];
}
$mysql_db = 'example_database';
$mysql_host = 'localhost';
$mysql_user = 'example_user';
$mysql_pass = 'Kolosnjaj4321!';
if (isset($_POST['text'])) {
$text = $_POST['text'];
if (!empty($text)) {
$con = mysqli_connect($mysql_host, $mysql_user, $mysql_pass);
if (mysqli_select_db($con, $mysql_db)) {
$query = "INSERT INTO `data` VALUES(NULL,'" . mysqli_real_escape_string($con, $text) . "')";
if ($query_run = mysqli_query($con, $query)) {
echo 'You are successfuly insert data in database';
}
} else {
echo 'not connected';
}
}
}