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!

Attachments
<html>
<body style="background-color:powderblue;">
      <?php


       include("c:\wamp\www\conf.php");

      

                   if(isset($_GET['autoid']))
                    {
                  $connection=@mysql_connect($host, $user, $pass)or die("Unable to connect!");
                  mysql_select_db($db, $connection) or die ('Unable to select database!');
                   $id=$_GET['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>


        

</body>
 </html>

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

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..

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.

Attachments
<html>
<body style="background-color:powderblue;">

          <?php
          include("c:\wamp\www\login.php");
           include("c:\wamp\www\conf.php");
                  $name2= $_COOKIE["cookiename"];

                  $connection=@mysql_connect($host, $user, $pass)or die("Unable to connect!");
                  mysql_select_db($db, $connection) or die ('Unable to select database!');

                $query2= "select title,category,year,autoid from movie where user='$name2'";
                $result2=mysql_query($query2);

          ?>
           </br> </br> </br> </br> </br>


           <p style"text-align:center;font-size:23"><a name="rubrik">Your proposal:</a></p>
              <font size="2"><a href="add.php" >add title</a></font>
           
            <div style="text-align:center">
           <table width="800" border="1">
                   <th>Title</th><th>Category</th><th>Year</th><th>&nbsp</th><th>&nbsp</th>
           <?php



                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>'.
           '</tr>';
               }


           ?>

        </table> </div>
</body>
 </html>

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... : )

This article has been dead for over six months. Start a new discussion instead.