^Bart
unread,May 1, 2020, 11:34:25 AM5/1/20You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Salve,
stavo dando un'occhiata a degli esercizi di php ma questo script non
riesco a farlo andare, si tratta di una semplice form per inserire un
record in un db:
<!DOCTYPE html>
<!-- TEST INSERIMENTO 28/03/2020 -->
<html lang="it">
<head>
<title>Add continent</title>
<meta charset="UTF-8" name="viewport" content="width=device-width,
initial-scale=1">
<link rel="stylesheet" href="css/w3.css">
</head>
<body>
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
return $data;
}
// mysql_connect(server,username,password)
include("conn.php");
mysqli_query($conn,"SET names \"UTF8\"");
if (isset($_POST) && isset($_POST['action']))
{
// form caricata tramite operazione POST
if ($_POST['action'] == 'ok')
{
$name = test_input($_POST['continentname']);
$sql = "INSERT INTO continents
('name')
VALUES ('".$name."')";
echo $sql;
$result = mysqli_query($conn, $sql);
//$stmt=$conn->prepare($sql);
//$stmt->execute();
//$result=$stmt->get_result();
if ($result == true)
{
?>
<p>Inserimento completato</p>
<?php
}
?>
<a href="continents.php">Torna indietro</a>
<?php
}
}
else
{
echo "Unable to save the name";
}
?>
<div class="w3-container">
<h2>Inserisci Utente</h2>
<form class="w3-form-all w3-card-4" name="modulo"
action="continentsaddform.php?id=<?=$_GET['id']?>" method="post">
<div class="w3-row w3-card-4">
<div class="w3-row w3-third w3-container">
<label for="fname">Nome:</label>
</div>
<div class="w3-twothird w3-container">
<input type="text" name="continentname" value="<?=$row["name"]?>"
placeholder="Inserire nome">
</div>
<input type="hidden" name="action" value="ok">
<div class="w3-row w3-third w3-container">
<input type="submit" name="submit" value="SALVA"><br>
</div>
</div>
</form>
</div>
</body>
</html>