Re: PHP & MySQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jason Pruim escribió:
Hi Everyone,

I know this isn't strictly a PHP question, and I apologize in advance for that. I'm trying to setup a website for some of my customers that would allow them to update a database on their schedule, making it easier for us to have the most up to date info, and taking some of the work off of us.

Right now, the question I have is, how would I be able to select certain records to be deleted (Or moved to another table called "deleted")? Is it as simple as looping through the database, having them check a checkbox, and then hit a "remove" button?

As I go, I will be adding a login screen to it, and hopefully protecting against SQL injection attacks... But right now, I'm still just learning and trying.

The SQL syntax is easy enough for me to figure out, but the php is throwing me off right now...

I'm running PHP 5.2.0
MySQL 5.0.24A

Any points to the right documents are greatly appreciated as well as sample code :)

Currently here is the code I'm working with on the page to display it:

$link = mysql_connect($server, $username, $password)
    or die('Could not connect: ' . mysql_error());
echo 'Connected successfully <BR>';
mysql_select_db('legion') or die('Could not select database' . mysql_error());
echo 'DB selected <BR>';



$result = mysql_query("SELECT * FROM current") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$FName = $row["FName"];
$LName = $row["LName"];
$Add1 = $row["Add1"];
$Add2 = $row["Add2"];
$City = $row["City"];
$State = $row["State"];
$Zip = $row["Zip"];
$Date = $row["Date"];


echo "$FName, $LName,  $Add1, $Add2, $City, $State, $Zip, $Date<BR>";
};

I'm sure there is an easier way to do that as well... But this way worked :)

Jason


Well, first of all you need to get the IDs of the rows you want to remove and then you will do something like:

DELETE FROM <table> WHERE id IN (<list of IDs to remove>)

You will need to show a list of removable records to the client as a list; for example:

   John Doe #1
   John Doe #2
   .
   .
   John Doe #n

with a checkbox every one of them. The when you hit submit in the form you just send the IDs to the php script...

--
Miguel J. Jiménez
Programador Senior
Área de Internet/XSL/PHP
migueljose.jimenez@xxxxxxxxxxx

----------------------------------------------------

ISOTROL
Edificio BLUENET, Avda. Isaac Newton nº3, 4ª planta.
Parque Tecnológico Cartuja '93, 41092 Sevilla (ESP).
Teléfono: +34 955 036 800 - Fax: +34 955 036 849
http://www.isotrol.com

"You let a political fight  come between you and your best friend you have in all the world. Do you realize how foolish that is? How ominous? How can this country survive if friends can't rise above the quarrel".
Constance Hazard, North & South (book I)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux