Skip to content
Advertisement

MED Schularberit

I have made a form which collets data form user and sendes them to the database,I wanted to add an addtional option to delete records that user choose.Im having trouble doing that and I would be very thankful i you cound help me.I am new in PHP so sorry that maybe I have done some “stupid” mistakes

The error I get:Notice: Undefined index: name in /var/customers/webs/harlac17/med3/shopping/delete.php on line 27

Code list.php Here are the POST data sent to Database and than showed in Web

JavaScript

Code delete.php

JavaScript

new.php Form with POST data

JavaScript

Advertisement

Answer

Firstly, don’t include your SQL passwords on Stack Overflow 😀

You will want to take a look at a couple of things here, note the try/catch (exceptions) usage, this is a good way of catching errors using PDO to show you where you are going wrong (read: https://www.php.net/manual/en/language.exceptions.php)

Also note how my sql string doesn’t have the variable directly entered. This is bad practice and can leave your application open to sql injection vulnerabilities. Always escape your SQL commands using PDO->execute(). (read: https://doc.bccnsoft.com/docs/php-docs-7-en/pdostatement.execute.html)

For the ‘Undefined index: name’ error, you want to check if $_POST[‘name’] actually exists before you use it.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement