Centrek Posted April 7, 2003 Share Posted April 7, 2003 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! Quote Link to comment https://forums.phpfreaks.com/topic/319-drop-down-listing-and-deleting-entries/ Share on other sites More sharing options...
DocSeuss Posted April 7, 2003 Share Posted April 7, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/319-drop-down-listing-and-deleting-entries/#findComment-1027 Share on other sites More sharing options...
Centrek Posted April 7, 2003 Author Share Posted April 7, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/319-drop-down-listing-and-deleting-entries/#findComment-1028 Share on other sites More sharing options...
DocSeuss Posted April 7, 2003 Share Posted April 7, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/319-drop-down-listing-and-deleting-entries/#findComment-1029 Share on other sites More sharing options...
Centrek Posted April 7, 2003 Author Share Posted April 7, 2003 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? Quote Link to comment https://forums.phpfreaks.com/topic/319-drop-down-listing-and-deleting-entries/#findComment-1030 Share on other sites More sharing options...
DocSeuss Posted April 7, 2003 Share Posted April 7, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/319-drop-down-listing-and-deleting-entries/#findComment-1031 Share on other sites More sharing options...
Centrek Posted April 7, 2003 Author Share Posted April 7, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/319-drop-down-listing-and-deleting-entries/#findComment-1035 Share on other sites More sharing options...
Centrek Posted April 10, 2003 Author Share Posted April 10, 2003 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! Quote Link to comment https://forums.phpfreaks.com/topic/319-drop-down-listing-and-deleting-entries/#findComment-1081 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.