note 127041 added to function.mysql-insert-id
| From: | anonymous at main dot php dot net | Date: | Mon, 09 May 2022 08:48:50 +0000 |
| Subject: | note 127041 added to function.mysql-insert-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218364@lists.php.net to get a copy of this message | ||
Is this a correct way of inserting data to mysql database
<?php
require 'db.php';
$message = '';
if (isset ($_POST['name']) && isset($_POST['last_name']) &&
isset($_POST['email']) && isset($_POST['class']) ) {
$name = $_POST['name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$class = $_POST['class'];
$sql = 'INSERT INTO people(name, last_name, email, class) VALUES(:name, :last_name, :email,
:class)';
$statement = $connection->prepare($sql);
if ($statement->execute([':name' => $name, ':last_name' =>
$last_name, ':email' => $email, ':class' => $class])) {
$message = 'Kandidaat aangemaakt';
}
}
?>
<?php require 'header.php'; ?>
<div class="container">
<div class="card mt-5">
<div class="card-header">
<h2>Create a person</h2>
</div>
<div class="card-body">
<?php if(!empty($message)): ?>
<div class="alert alert-success">
<?= $message; ?>
</div>
<?php endif; ?>
<form method="post">
<div class="form-group">
<label for="name">Naam</label>
<input type="text" name="name" id="name"
class="form-control">
</div>
<div class="form-group">
<label for="name">Achternaam</label>
<input type="text" name="last_name" id="last_name"
class="form-control">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" id="email"
class="form-control">
</div>
<div class="form-group">
<label for="email">Klas</label>
<input type="text" name="class" id="class"
class="form-control">
</div>
<div class="form-group">
<button type="submit" class="btn btn-info">Maak
kandidaat</button>
</div>
</form>
</div>
</div>
</div>
<?php require 'footer.php'; ?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.47 (proxied: 85.148.255.67)
----
Manual Page -- https://php.net/manual/en/function.mysql-insert-id.php
Edit -- https://main.php.net/note/edit/127041
Del: integrated -- https://main.php.net/note/delete/127041/integrated
Del: useless -- https://main.php.net/note/delete/127041/useless
Del: bad code -- https://main.php.net/note/delete/127041/bad+code
Del: spam -- https://main.php.net/note/delete/127041/spam
Del: non-english -- https://main.php.net/note/delete/127041/non-english
Del: in docs -- https://main.php.net/note/delete/127041/in+docs
Del: other reasons-- https://main.php.net/note/delete/127041
Reject -- https://main.php.net/note/reject/127041
Search -- https://main.php.net/manage/user-notes.php