[PHP] Re: deleting a record.
? // get the list of resellers from the db $res = mysql_query(SELECT * FROM resellers ORDER BY id); // print all records in the DB while ($myrow = mysql_fetch_array($res)){ echo trtddiv align='center'font class=\content\.$myrow['id']./font/div /tdtdnbsp;/tdtddiv align='justify'font class=\content\.$myrow['company']./font/div/td; printf(tdfont class='content'a href=\%s?op=resellersid=%sdelete=yes\(DELETE)/a/font/td/tr, $PHP_SELF, $myrow[id]); }? There's an easier way to display this. It should make your life easier...made mine. Take a look: ? // get the list of resellers from the db $res = mysql_query(SELECT * FROM resellers ORDER BY id); // print all records in the DB while ($myrow = mysql_fetch_array($res)): ? trtddiv align='center' font class=content?=$myrow['id']?/font /div/tdtdnbsp;/tdtd div align='justify'font class=content ?=$myrow['company']?/font/div/tdtdfont class=content a href=?=$PHP_SELF??op=resellersid=?=$myrow['id']?delete=yes (DELETE)/a/font/td/tr ? endwhile; ? now when I click on delete it just reloads the page and doesn't delete the record. I have this code before anything else on the page to handle the delete... if($delete){ $res= mysql_query(DELETE FROM resellers WHERE id=$id); header(Location: admin2.php?op=resellers); } What you should do here is check to see if $res is failing, simply by doing the following: if(!$res) echo error; Then, place an 'exit;' after the header(...) command to see if the $delete variable is actually being passed. -- Kyle Gibson admin(at)frozenonline.com http://www.frozenonline.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: deleting a record.
Thanks Kyle, got it working like a treat :) for some reason it wasn't selecting the DB but it is now :D -Original Message- From: Kyle Gibson [mailto:[EMAIL PROTECTED]] Sent: Wednesday, 27 November 2002 10:05 AM To: [EMAIL PROTECTED] Subject: [PHP] Re: deleting a record. ? // get the list of resellers from the db $res = mysql_query(SELECT * FROM resellers ORDER BY id); // print all records in the DB while ($myrow = mysql_fetch_array($res)){ echo trtddiv align='center'font class=\content\.$myrow['id']./font/div /tdtdnbsp;/tdtddiv align='justify'font class=\content\.$myrow['company']./font/div/td; printf(tdfont class='content'a href=\%s?op=resellersid=%sdelete=yes\(DELETE)/a/font/td/tr, $PHP_SELF, $myrow[id]); }? There's an easier way to display this. It should make your life easier...made mine. Take a look: ? // get the list of resellers from the db $res = mysql_query(SELECT * FROM resellers ORDER BY id); // print all records in the DB while ($myrow = mysql_fetch_array($res)): ? trtddiv align='center' font class=content?=$myrow['id']?/font /div/tdtdnbsp;/tdtd div align='justify'font class=content ?=$myrow['company']?/font/div/tdtdfont class=content a href=?=$PHP_SELF??op=resellersid=?=$myrow['id']?delete=yes (DELETE)/a/font/td/tr ? endwhile; ? now when I click on delete it just reloads the page and doesn't delete the record. I have this code before anything else on the page to handle the delete... if($delete){ $res= mysql_query(DELETE FROM resellers WHERE id=$id); header(Location: admin2.php?op=resellers); } What you should do here is check to see if $res is failing, simply by doing the following: if(!$res) echo error; Then, place an 'exit;' after the header(...) command to see if the $delete variable is actually being passed. -- Kyle Gibson admin(at)frozenonline.com http://www.frozenonline.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Deleting a Record
[EMAIL PROTECTED] (Chuck \Pup\ Payne) wrote: Hi, I a seting up a php page that will let me delete a record from my mysql database, but I want it be able to match to fields before it will let a user delete that record. I know the basic sql command is DELETE FROM $table WHERE field 1 = $value But I don't know how to write the state for a second field. Can some one tell, but one field seem to give too much choose and would make it to easy to delete the wrong record. DELETE FROM table WHERE field = 1 AND field2 = 2 -- Henrik Hansen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Deleting a Record
First of all, make a copy of your database to test things. Never test code on production enviroment. Then, the delete syntax most of the time is: DELETE FROM table_name WHERE column = 'value'; Let's see: ?php $table = 'table_name'; $value = '15'; $sql = DELETE FROM $table WHERE field_1 = '$value'; mysql_query($sql) or exit(mysql_error()); ? There isn't a space between field and 1, at least I don't think SQL compliant databases let you put spaces on table and column names. $value probaly should be between single quotes, Mysql requires it for strings or values that are compared to a string type-column (varchar, text, etc...). Even sometimes for numeric columns, so, doesn't hurt to leave it unless it doesn't work ;-) If $table is not recognized, try: $sql = 'DELETE FROM ' . $table . WHERE field_1 = '$value'; If you just want to delete one record, it's a good idea to put a LIMIT 1 at the end. Hope it helps! -- Julio Nobrega. Um dia eu chego lá: http://sourceforge.net/projects/toca Ajudei? Salvei? Que tal um presentinho? http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884 Chuck Pup Payne [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... Hi, I a seting up a php page that will let me delete a record from my mysql database, but I want it be able to match to fields before it will let a user delete that record. I know the basic sql command is DELETE FROM $table WHERE field 1 = $value But I don't know how to write the state for a second field. Can some one tell, but one field seem to give too much choose and would make it to easy to delete the wrong record. | Chuck Payne | | Magi Design and Support | | [EMAIL PROTECTED] | BeOS, Macintosh 68K, Classic, and OS X, Linux Support. Web Design you can afford. Never be bullied into silence. Never allow yourself to be made a victim. Accept no one's definition of your life; define yourself.- Harvey Fierstein -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Deleting a Record
At 7:46 -0500 3/6/02, Chuck \PUP\ Payne wrote: Hi, I a seting up a php page that will let me delete a record from my mysql database, but I want it be able to match to fields before it will let a user delete that record. I know the basic sql command is DELETE FROM $table WHERE field 1 = $value But I don't know how to write the state for a second field. Can some one tell, but one field seem to give too much choose and would make it to easy to delete the wrong record. Connect the conditions with AND: DELETE FROM tbl_name WHERE col1 = 'value1' AND col2 = 'value2' | Chuck Payne | | Magi Design and Support | | [EMAIL PROTECTED] | BeOS, Macintosh 68K, Classic, and OS X, Linux Support. Web Design you can afford. Never be bullied into silence. Never allow yourself to be made a victim. Accept no one's definition of your life; define yourself.- Harvey Fierstein -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Deleting a Record
Thanks I have now five ways to try. | Chuck Payne | | Magi Design and Support | | [EMAIL PROTECTED] | -Original Message- From: Paul DuBois [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 06, 2002 10:43 AM To: Chuck PUP Payne; [EMAIL PROTECTED] Cc: PHP General Subject: Re: Deleting a Record At 7:46 -0500 3/6/02, Chuck \PUP\ Payne wrote: Hi, I a seting up a php page that will let me delete a record from my mysql database, but I want it be able to match to fields before it will let a user delete that record. I know the basic sql command is DELETE FROM $table WHERE field 1 = $value But I don't know how to write the state for a second field. Can some one tell, but one field seem to give too much choose and would make it to easy to delete the wrong record. Connect the conditions with AND: DELETE FROM tbl_name WHERE col1 = 'value1' AND col2 = 'value2' | Chuck Payne | | Magi Design and Support | | [EMAIL PROTECTED] | BeOS, Macintosh 68K, Classic, and OS X, Linux Support. Web Design you can afford. Never be bullied into silence. Never allow yourself to be made a victim. Accept no one's definition of your life; define yourself.- Harvey Fierstein - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php