I have a SQL databases of users forms, and want to set up some routine or maybe even PHP that will automatically delete empty rows which looks like this:
Column1=(Name=John Surname=Doe) | Column2=(Name=John Surname=) | Column3=(Name=John Surname=Doe)
In this case I would like for database to automatically delete Column2 because surname is missing…
Manually, I could do it like this:
DELETE FROM myTable WHERE Surname='';
Can this be helpful? Never used it.
Or to make some PHP script on load of my website and onload of display of my table (I forgot to mention that I have another web page where I view my table…) which will delete emtpy rows, aka run this code: DELETE FROM myTable WHERE Surname='';
I cannot forbid or put required on my input form because of other reasons…
Any help is apricated, thank You.
2
Answers
First solution:
In Cpanel/DirectAdmin/… create a
Cron Job
for PHP.Second solution:
Third solution:
When running the script related to the table, put the delete command.
Add trigger. This will remove the inserted row inmediatly. The
new
keyword is for access the columns in the inserted rowreplace
id
with the primary key of myTableAnother solution could be adding
NOT NULL
constraint on surname column to prevent insert row like this. Depending on how you handle result of the insert query, probably you will need to add some lines to your code add to avoid breaking of the posterior logic