Not able to delete a title...help please!

Reply

Join Date: Sep 2008
Posts: 28
Reputation: totalnoob is an unknown quantity at this point 
Solved Threads: 0
totalnoob totalnoob is offline Offline
Light Poster

Not able to delete a title...help please!

 
0
  #1
Apr 9th, 2009
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:
  1. echo '<tr>'.
  2. '<td>'.$row['title'].'</td>'.'<td>'.$row['category'].'</td>'.'<td>'.$row['year'].'</td>'.
  3. '<td>'.'<font size="2"><a href="edit.php?autoid="'.$row['autoid'].'">
  4. edit</a></font>'.'</td>'.'<td>'.'<font size="2"><a href="delete.php?autoid="'.$row['autoid'].'" >delete</a></font>'.'</td>'.
  5. '</tr>';
And I've attached the delete.php file.
Thanks in advance!
Last edited by peter_budo; Apr 10th, 2009 at 10:18 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Attached Files
File Type: php delete.php (951 Bytes, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,361
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 164
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Not able to delete a title...help please!

 
0
  #2
Apr 9th, 2009
it is unneccessary, and often makes you miss a quote, to drop in and out of php text for every html tag
  1. echo '<tr><td>'.$row['title'].'</td><td>'.$row['category'].'</td><td>'.$row['year'].'</td>
  2. <td><font size="2"><a href="edit.php?autoid="'.$row['autoid'].'"> edit </a></font></td>
  3. <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
Last edited by almostbob; Apr 9th, 2009 at 10:32 am.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: Not able to delete a title...help please!

 
0
  #3
Apr 9th, 2009
try $_REQUEST['autoid'] instead of $_GET['autoid']
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: Not able to delete a title...help please!

 
0
  #4
Apr 9th, 2009
use this code, becuase you dont have form in ur first html section

  1. if(isset($_REQUEST['autoid']))
  2. {
  3.  
  4. $connection=@mysql_connect($host, $user, $pass)or die("Unable to connect!");
  5. mysql_select_db($db, $connection) or die ('Unable to select database!');
  6. $id=$_REQUEST['autoid'] ;
  7. $query4= "delete from movie where autoid=$id";
  8. $result2=mysql_query($query4) or die ("query failed!");
  9.  
  10. echo "Title deleted";
  11. ?>
  12. </br> </br> </br> </br> </br>
  13. <?php
  14. }
  15. else
  16. {
  17. echo "not deleted!";
  18. }
  19. ?>
  20.  
  21. <a href="members.php">Back to main page</a>
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 28
Reputation: totalnoob is an unknown quantity at this point 
Solved Threads: 0
totalnoob totalnoob is offline Offline
Light Poster

Re: Not able to delete a title...help please!

 
0
  #5
Apr 9th, 2009
Originally Posted by almostbob View Post
it is unneccessary, and often makes you miss a quote, to drop in and out of php text for every html tag
  1. echo '<tr><td>'.$row['title'].'</td><td>'.$row['category'].'</td><td>'.$row['year'].'</td>
  2. <td><font size="2"><a href="edit.php?autoid="'.$row['autoid'].'"> edit </a></font></td>
  3. <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..
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,361
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 164
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Not able to delete a title...help please!

 
0
  #6
Apr 9th, 2009
BzzBee nailed it
the field isnt populated

if(isset($_REQUEST['autoid']))
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 28
Reputation: totalnoob is an unknown quantity at this point 
Solved Threads: 0
totalnoob totalnoob is offline Offline
Light Poster

Re: Not able to delete a title...help please!

 
0
  #7
Apr 9th, 2009
Originally Posted by BzzBee View Post
use this code, becuase you dont have form in ur first html section

  1. if(isset($_REQUEST['autoid']))
  2. {
  3.  
  4. $connection=@mysql_connect($host, $user, $pass)or die("Unable to connect!");
  5. mysql_select_db($db, $connection) or die ('Unable to select database!');
  6. $id=$_REQUEST['autoid'] ;
  7. $query4= "delete from movie where autoid=$id";
  8. $result2=mysql_query($query4) or die ("query failed!");
  9.  
  10. echo "Title deleted";
  11. ?>
  12. </br> </br> </br> </br> </br>
  13. <?php
  14. }
  15. else
  16. {
  17. echo "not deleted!";
  18. }
  19. ?>
  20.  
  21. <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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 148
Reputation: mschroeder is on a distinguished road 
Solved Threads: 25
mschroeder mschroeder is offline Offline
Junior Poster

Re: Not able to delete a title...help please!

 
0
  #8
Apr 9th, 2009
Then the problem is in the code prior to:

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

as it doesn't appear to actually be returning an autoid.
If you're question/problem is solved don't forget to mark the thread as Solved!

-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 28
Reputation: totalnoob is an unknown quantity at this point 
Solved Threads: 0
totalnoob totalnoob is offline Offline
Light Poster

Re: Not able to delete a title...help please!

 
0
  #9
Apr 9th, 2009
Originally Posted by mschroeder View Post
Then the problem is in the code prior to:

  1. echo '<tr>'.
  2. '<td>'.$row['title'].'</td>'.'<td>'.$row['category'].'</td>'.'<td>'.$row['year'].'</td>'.
  3. '<td>'.'<font size="2"><a href="edit.php?autoid="'.$row['autoid'].'">
  4. edit</a></font>'.'</td>'.'<td>'.'<font size="2"><a href="delete.php?autoid="'.$row['autoid'].'" >delete</a></font>'.'</td>'.
  5. '</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.
Attached Files
File Type: php members.php (1.5 KB, 0 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 28
Reputation: totalnoob is an unknown quantity at this point 
Solved Threads: 0
totalnoob totalnoob is offline Offline
Light Poster

Re: Not able to delete a title...help please!

 
0
  #10
Apr 9th, 2009
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:
  1. while ($row = mysql_fetch_assoc($result2))
  2. {
  3. echo '<tr>'.
  4. '<td>'.$row['title'].'</td>'.'<td>'.$row['category'].'</td>'.'<td>'.$row['year'].'</td>'.
  5. '<td>'.'<font size="2"><a href="edit.php?autoid="'.$row['autoid'].'">
  6. edit</a></font>'.'</td>'.'<td>'.'<font size="2"><a href="delete.php?autoid="'.$row['autoid'].'" >delete</a></font>'.'</td>'.
  7. '<td>'.$row['autoid'].
  8. '</tr>';
  9. }
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...
Last edited by totalnoob; Apr 9th, 2009 at 11:22 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC