PHP-Intro 11 Databases in PHP using PDO (Part 1)

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

At 15:36 "Lets put some data in a database!", discussing the code user1.php, slide 16.

isset($_POST['name']) will always be true! It doesn't matter if you enter anything in the form, even if you leave everything blank and click "Add New" the code will be executed.

So, I changed it to: if ( !empty($_POST['name']) && !empty($_POST['email'])
&& !empty($_POST['password'])) { ....

I'm using PHP Version 7.0.13

johnc
Автор

if your finding problems with the user2del.php file.
try to change the 'user_id' into 'id' or copy the code below.



<?php
require_once "pdo.php";

if ( isset($_POST['id']) ) { //changed 'user_id' into 'id'
$sql = "DELETE FROM users WHERE id = :zip"; //changed 'user_id' into 'id'
echo "<pre>\n$sql\n</pre>\n";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(':zip' => $_POST['id'])); //changed 'user_id' into 'id'
}
?>
<p>Delete A User</p>
<form method="post">
<p>ID to Delete:
<input type="text" name="id"></p> <!--changed name="user_id" into name="id"--->
<p><input type="submit" value="Delete"/></p>
</form>






I hope this was help full 👍🏻

harrydoorein
welcome to shbcf.ru