File sample.html
<form action="sample.php" method="POST">
<input name="sample" type="text">
<input name="submit" type="submit" value="Submit">
</form>
File contoh.php
<?php
if (isset($_POST['submit'])) {
$mysqli = new mysqli('localhost', 'user', 'password', 'mysampledb');
/* Check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = $mysqli->prepare("INSERT INTO SampleTable VALUES (?)");
$stmt->bind_param('s', $sample); // Bind $sample to the parameter
$sample = isset($_POST['sample'])
? $_POST['sample']
: '';
/* Execute prepared statement */
$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
/* Close statement and connection */
$stmt->close();
/* Close connection */
$mysqli->close();
}
?>
Ini adalah contoh yang sangat mendasar. Banyak pengembang PHP saat ini beralih ke PDO . Mysqli tidak ketinggalan zaman, tetapi PDO banyak lebih mudah, IMHO.