Hello everyone!
I have a table with titles that have a link to delete the record.
Clicking on the link, redirects the user from (members.php) to a page (delete.php )where it says that the title is deleted and the user can click another link to return to the table. The problem is that the title is never deleted. Could anyone please tell me what's wrong with my code?
This is the table that redirects the user:

echo '<tr>'.
           '<td>'.$row['title'].'</td>'.'<td>'.$row['category'].'</td>'.'<td>'.$row['year'].'</td>'.
           '<td>'.'<font size="2"><a href="edit.php?autoid="'.$row['autoid'].'">
           edit</a></font>'.'</td>'.'<td>'.'<font size="2"><a href="delete.php?autoid="'.$row['autoid'].'" >delete</a></font>'.'</td>'.
           '</tr>';

And I've attached the delete.php file.
Thanks in advance!

it is unneccessary, and often makes you miss a quote, to drop in and out of php text for every html tag

echo '<tr><td>'.$row['title'].'</td><td>'.$row['category'].'</td><td>'.$row['year'].'</td>
<td><font size="2"><a href="edit.php?autoid="'.$row['autoid'].'">  edit </a></font></td>
<td><font size="2"><a href="delete.php?autoid="'.$row['autoid'].'" >delete</a></font></td></tr>';

when it displays the table, view source to make sure the delet <a href ?parameter is populated with an id, stranger things happen, the error may be in the prior sql query
and $query4= "delete from movie where autoid='$id'"; looks right

try $_REQUEST instead of $_GET

use this code, becuase you dont have form in ur first html section

if(isset($_REQUEST['autoid']))
                    {

                  $connection=@mysql_connect($host, $user, $pass)or die("Unable to connect!");
                  mysql_select_db($db, $connection) or die ('Unable to select database!');
                   $id=$_REQUEST['autoid'] ;
                $query4= "delete from movie where autoid=$id";
                $result2=mysql_query($query4) or die ("query failed!");

                     echo "Title deleted";
              ?>
                    </br> </br> </br> </br> </br>
              <?php
                    }
                    else
                    {
                      echo "not deleted!";
                    }
            ?>

                  <a href="members.php">Back to main page</a>

it is unneccessary, and often makes you miss a quote, to drop in and out of php text for every html tag

echo '<tr><td>'.$row['title'].'</td><td>'.$row['category'].'</td><td>'.$row['year'].'</td>
<td><font size="2"><a href="edit.php?autoid="'.$row['autoid'].'">  edit </a></font></td>
<td><font size="2"><a href="delete.php?autoid="'.$row['autoid'].'" >delete</a></font></td></tr>';

when it displays the table, view source to make sure the href ?parameter is populated with an id, stranger things happen
and $query4= "delete from movie where autoid='$id'"; if the id is numeric, may not need the single quotes around it in the sql $query4= "delete from movie where autoid=$id";

Hi!
Thanks for your reply! I've tried the query without the single quotes and now it says quey failed in the page.
When I looked in the URL it looked like this:
http://localhost/delete.php?autoid=

There is no id number after autoid. It's like it never recieved a number..

BzzBee nailed it
the field isnt populated if(isset($_REQUEST['autoid']))

use this code, becuase you dont have form in ur first html section

if(isset($_REQUEST['autoid']))
                    {

                  $connection=@mysql_connect($host, $user, $pass)or die("Unable to connect!");
                  mysql_select_db($db, $connection) or die ('Unable to select database!');
                   $id=$_REQUEST['autoid'] ;
                $query4= "delete from movie where autoid=$id";
                $result2=mysql_query($query4) or die ("query failed!");

                     echo "Title deleted";
              ?>
                    </br> </br> </br> </br> </br>
              <?php
                    }
                    else
                    {
                      echo "not deleted!";
                    }
            ?>

                  <a href="members.php">Back to main page</a>

Hi!
Thank you for your reply!
I've tried replacing get to request, but it still says query failed.

Then the problem is in the code prior to:

echo '<tr>'.
'<td>'.$row['title'].'</td>'.'<td>'.$row['category'].'</td>'.'<td>'.$row['year'].'</td>'.
'<td>'.'<font size="2"><a href="edit.php?autoid="'.$row['autoid'].'">
edit</a></font>'.'</td>'.'<td>'.'<font size="2"><a href="delete.php?autoid="'.$row['autoid'].'" >delete</a></font>'.'</td>'.
'</tr>';

as it doesn't appear to actually be returning an autoid.

Then the problem is in the code prior to:

echo '<tr>'.
'<td>'.$row['title'].'</td>'.'<td>'.$row['category'].'</td>'.'<td>'.$row['year'].'</td>'.
'<td>'.'<font size="2"><a href="edit.php?autoid="'.$row['autoid'].'">
edit</a></font>'.'</td>'.'<td>'.'<font size="2"><a href="delete.php?autoid="'.$row['autoid'].'" >delete</a></font>'.'</td>'.
'</tr>';

as it doesn't appear to actually be returning an autoid.

I'm looking into it right now. Here's the members.php file that has the table, if your interested in seeing it.

I've made small change in the table, just to see if the autoid numbers appeared and it did! I added an extra row.
This is what I did:

while ($row = mysql_fetch_assoc($result2))
               {
      echo '<tr>'.
           '<td>'.$row['title'].'</td>'.'<td>'.$row['category'].'</td>'.'<td>'.$row['year'].'</td>'.
           '<td>'.'<font size="2"><a href="edit.php?autoid="'.$row['autoid'].'">
           edit</a></font>'.'</td>'.'<td>'.'<font size="2"><a href="delete.php?autoid="'.$row['autoid'].'" >delete</a></font>'.'</td>'.
           '<td>'.$row['autoid'].
           '</tr>';
               }

It extracts the autoid number and shows it in the table, but somehow it doesn't pass the value to the url or the query in the other file...

Thank all of you for your replies!
I haven't figured out the problem yet, but I'm going to work with it again later on....
If anyone has figured it out, your more then welcome to reply to the thread... : )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.