Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-30-2008, 11:22 AM deleting rows......
Junior Talker

Posts: 1
Name: pritam
Trades: 0
I have a PHP script that displays data from mysql in a nice tabular format. I have included a link along with each row. Now what i want is that on clicking link corresponding to a row should delete the entire row from the page as well from the MySql database. This is my code so far....Please help.


************ display_notes.php *******************


<?php
$query ="SELECT date, note FROM notes";
$result = mysql_query($query);
$count=mysql_num_rows($result);
if ($count == 0) {
echo "<br><br><strong>No notes found in database</strong>";
}
else {
echo '<table style="width: 400px" align="center" border="1px">';
echo '<tr>';
echo '<td style="width: 100px"><b>Date</b></td>';
echo '<td style="width: 300px"><b>Note</b></td>';
echo '</tr>';
while (list($date, $note) = mysql_fetch_row($result)):
echo '<tr>';
echo '<td style="width: 100px">'.$date.'</td>';
echo '<td style="width: 300px">'.$note.'</td>';
echo '<td style="border: 0px">';
echo '<a href="delete_notes.php?rec=$N_ID">DELETE</td>';
echo '</tr>';
endwhile;
echo '</table>';
}
?>
************************************************** ***************


************** delete_notes.php *****************************


<?php
mysql_query("DELETE FROM notes WHERE N_ID=$N_ID");
#if (!mysql_query($sql,$conn))
#{
#die('Error: ' . mysql_error());
#}
?>
************************************************** ***************
pritam79 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-30-2008, 06:26 PM Re: deleting rows......
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Add $N_ID = mysql_real_escape($_GET['N_ID']); before that...

and it should work.. but thats not very good code and can probably easily hacked


Hope this helps and Rep will be apprieciated
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 03-31-2008, 12:54 AM Re: deleting rows......
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
AFAIS, N_ID is not defined anywhere in your code, so it won't work.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 03-31-2008, 07:48 AM Re: deleting rows......
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
i didnt look at the first code, good point.

im guessing you need to add N_ID to the select wuery to retrieve the info and then use mysql_fetch_array() to get it.

Which u should be using to get $note etc too...

You should really revise your Mysql functions
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to deleting rows......
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13560 seconds with 12 queries