Jump to content

Drop Down listing and Deleting Entries


Centrek

Recommended Posts

I\'m working on some code to create a DB of clients. Each client will be listed in a drop down list.

The code for the list is just HTML....

 

$temp=\'<option value=\" \"> %n </option>\';

 

 

 

This puts all of the names in the list, but I need to be able to use the ID number so that I can delete it like this...

 

mysql_query(\"DELETE FROM clients WHERE id=\'$num\'\") or $error=true;

 

 

 

This is my code to get the information from the DB:

 

while($result = mysql_fetch_array(mysql_query(\'SELECT * FROM clients WHERE id<\' . $max . \' ORDER BY id DESC;\')))

{

$n = $_POST[\'name\'];

$e = $_POST[\'email\'];

$a = $_POST[\'aim\'];

$i = $_POST[\'icq\'];

$s = $_POST[\'site\'];

$l = date(\'F j Y\');

$num=$_POST[\'id\'];

echo str_replace(Array(\'%n\', \'%e\', \'%a\', \'%i\', \'%s\', \'%l\'), Array($result[\'name\'], $result[\'email\'], $result[\'aim\'], $result[\'icq\'], $result[\'site\'], $result[\'listed\']), $temp);

$max = $result[\'id\'];

}

 

 

I know i need something in the quotes in the <option value\" \"> tag, but nothing I try works.

 

Any help would be greatly appreciated!

Link to comment
Share on other sites

seems to me the value would be a variable that was equal to the client_id that is linked to the client name. And from here that looks like $num. I\'m sure that is what your looking for if it isn\'t working then we have a problem somewhere else with the code/logic.

Link to comment
Share on other sites


elseif(isset($_POST[\'delete\']))

{

mysql_query("DELETE FROM clients WHERE name=\'$num\'") or $error=true;



if(isset($error))

 {

 	echo \'HRMMMM  It\'s broken.<br><small>\' . mysql_error() . \'</small><br>\';

 	echo \'Click <a href="\' . $PHP_SELF . \'">HERE</a> to try again.\';

 }



else

 {

 	echo \'This client has now been deleted.  Let them try to find a better host!\';

 }

}



echo \'<form name="clientForm" action="\' . $PHP_SELF . \'" method="POST"><font color ="336699" size="1" Font="Arial"><font face="Arial">\';

?>

<select name="selector" onchange="showIt()" size="1">

<option selected value="">-- Select A Client --</option>

<?php

$temp = \'<option value="\' . $num . \'">%n</option>\';

$max = mysql_fetch_array(mysql_query(\'SELECT MAX(id) FROM clients\'));

$max = $max[\'MAX(id)\']+1;

while($result = mysql_fetch_array(mysql_query(\'SELECT * FROM clients WHERE id<\' . $max . \' ORDER BY id DESC;\')))

{

$n = $_POST[\'name\'];

$e = $_POST[\'email\'];

$a = $_POST[\'aim\'];

$i = $_POST[\'icq\'];

$s = $_POST[\'site\'];

$l = date(\'F j Y\');

$num=$_POST[\'id\'];

echo str_replace(Array(\'%n\', \'%e\', \'%a\', \'%i\', \'%s\', \'%l\'), Array($result[\'name\'], $result[\'email\'], $result[\'aim\'], $result[\'icq\'], $result[\'site\'],  $result[\'listed\']), $temp);

$max = $result[\'id\'];

}

?>

</select>



 

I get the statement: This client has now been deleted. Let them try to find a better host! So it doesn\'t have an error, and thinks that it deletes it, but it doesn\'t.

Link to comment
Share on other sites

Just think about the flow of the program, you are setting those correctly you are just doing it too late. Once the submit button is hit all the \'simple\' variables are gone. only the special variables (like post and get and session) will be available.

Link to comment
Share on other sites

i\'m really confused now!

 

while trying to debug a bit, i tried to change the following around:

$temp = \'<option value=\"\' . $num . \'\">%n</option>\';

 

$temp = \'<option value=\" \">%n</option>\'; produces the Names in the list

$temp = \'<option value=\" \">%i</option>\'; produces their ICQ #s in list

$temp = \'<option value=\" \">$n</option>\'; shows nothing

$temp = \'<option value=\" \">$i</option>\'; shows nothing

$temp = \'<option value=\" \">%num</option>\'; shows their Names with \'um\' appended to them in the list

 

I cannot get $num to show a value, even though I know it has one, least i think I know it has one.

Link to comment
Share on other sites

DocSeuss:

Thank you very much for your help, it did take me another couple days of tinkering, and a lot of thinking, but it got it! I\'m pretty happy!

There are a few things that i\'d like to be a bit different, but this does what it needs to for now!

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.