Jump to content


Photo

Drop Down listing and Deleting Entries


  • Please log in to reply
7 replies to this topic

#1 Centrek

Centrek
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 April 2003 - 05:06 PM

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!
568

#2 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 07 April 2003 - 05:16 PM

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.
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#3 Centrek

Centrek
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 April 2003 - 05:33 PM


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.
568

#4 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 07 April 2003 - 06:36 PM

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.
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#5 Centrek

Centrek
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 April 2003 - 08:01 PM

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?
568

#6 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 07 April 2003 - 08:52 PM

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.
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#7 Centrek

Centrek
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 April 2003 - 10:54 PM

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.
568

#8 Centrek

Centrek
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 10 April 2003 - 09:32 PM

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!
568




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users