Jump to content

Archived

This topic is now archived and is closed to further replies.

Centrek

Drop Down listing and Deleting Entries

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!

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

if isset($_POST[delete]) is true and you go into that if statement you have not yet pulled the value of $_POST[id] in the variable $num. Also I believe you want WHERE id=$num not name=$num.

Share this post


Link to post
Share on other sites

oh,

can you help me out by showing me how i would do that??

i thought that if i said $num=$_POST[\'id\']; that it would pass to the isset($_POST[\'delete\'])

 

what should i do here?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

×

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.