Help! creating forms from database info

I need to be able to delete specific files from a database via a form… I think. This may not be the correct way, so I’m up for suggestions. Anyways, I’m trying to name my form buttons based on the data in the database. Here’s my code: (q1, q2, q3, & file are rows in my database) In bold are what I think should work.

while($row = mysql_fetch_array($result))
{
echo “

”;
echo “” . $row[‘q1’] . “”;
echo “” . $row[‘q2’] . “”;
echo “” . $row[‘q3’] . “”;
echo “” . $row[‘file’] . “”;
echo “”
?>
      
<?php ; echo ""; echo ""; }

After you submit your form, you will need to run a DELETE query:

DELETE FROM your_table WHERE your_row = 'q1'

This is an example of how to delete a row from a table in SQL. Keep in mind that the ‘q1’ part can be variable, and as such a submitted value from the form. Be warned that if not secured sufficiently, malicious users may get creative with your script and delete your whole table (or perhaps even the whole database). Look up SQL injection on your favorite seach engine to read up the dangers of SQL queries and html forms.

Sponsor our Newsletter | Privacy Policy | Terms of Service