Jump to content

HELP!!!! Delete a selected <option> from dropdown-list populated by a MySQL-db


sleepysy

Recommended Posts

hey guys, i ( ... still newbie)  got following problem. The title describes it already very well ... i have managed to make my form do the addrecord-submission to mysql ... but not to let the user select an item in the dropdownlist to delete that (or another) selected record again. Does anyone know what i am doing wrong? This is my script:

 

<form id="formstyle" method="POST" action=<?php echo $PHP_SELF;?>>
<div class="line">
   <span class="labelname">Productfamily:</span> 
   <input  class="ffield1"           name="bereich" type="text" value="z.b. Design & Graphik">
      <select class="option_bereich_01" name="areas">   
         <?php                  
      	     session_start('speichern');
           
	   $_SESSION ['bereich'] = $_POST['bereich']; 
	   $check_bereich = $_POST['bereich'];
	        
	        include 'includes/connect.php';
	        

			if ($verbindung){
				mysqli_select_db($verbindung, $datenbank);
	            if(mysqli_error($verbindung)){
		 		echo "fehler";
		 	}else{
				$sql = "SELECT * FROM `bereich`
				ORDER BY `key`";
				$abfrage = mysqli_query($verbindung, $sql);
			    
			 }      
			};

      		while ($sel_bereich = mysqli_fetch_assoc($abfrage)){
	echo "<option VALUE=''>". $sel_bereich['key']." ". $sel_bereich['bereich']." </option>";
	}										 
        ?>
    </select>  

</div>
    <div id="msg">
  <?php 
        if (isset($_SESSION ['meldung'])){
             echo $_SESSION ['meldung']; 
        } else {  
             echo "Wert eingegeben!";   
        }     
      ?>  
    </div>
   

<div id="tasten-wrap_delete">   
   <div class="line"><input id="taste" name= "del" type="submit" value="Löschen" ></div>
</div>

<div id="tasten-wrap_bereich">   
   <div class="bt"><input id="taste" name= "sav" type="submit" value="Sichern" ></div>
</div>


</form>
-----------------------------  END index.php -----------------------------------


-----------------------------  bereiche.php -------------------------------------
<?php

<?php
session_start();

include 'includes/connect.php';

//some of theses session-vars i have just used for trying ... 

$delete =  $_SESSION ['delete_object'];
$bereich = $_SESSION ['bereich'];
$wahl =    $_SESSION ['choice'];
$area =    $_SESSION ['areas'];
$sel_b =   $_SESSION ['sel_bereich'];


if($wahl == 'delete' ){
  
  switch ($wahl){   
    case empty ($bereich):
		    $state_bereich = 'Bitte Eingabe machen!';
 		    $_SESSION ['meldung']  = $state_bereich;
		    break;
		    
    case ! empty ($bereich):
    		
    		$sql = "DELETE FROM `db6776223-powertraining`.`bereich` WHERE `bereich`.`key` = {$sel_b['key']};" ;
		        
	 		$abfrage = mysqli_query($verbindung, $sql);

	 		$state_bereich = $area.' wurde gelöscht';
 	 		$_SESSION ['meldung']  = $state_bereich;  

	 		header("location: index.php");
	 		exit; 
    
    break;	    
	}  
   } else {
   echo "not selected - failed!";
  	   }
?>

 

 

this is how it should look like :  http://www.schmoelz.at/redaktion/index.php

 

 

thanks in advance !!!!!

Where is $_SESSION['choice']; being declared? You're using it in the conditional if($wahl == 'delete' ){ without giving it a value.

 

You shouldn't use sessions to pass data from page to page. Sessions are meant to store an applications 'state' (if a user is logged on, etc), they aren't meant to pass information from page to page. Use $_GET or $_POST instead.

ooops. sorry. i forgot to paste the part of the script (in index.php on the very top) where i catch the submission values according to what the user clicks - save or delete record. here the $_SESSION ['choice'] is declared.

 

i always thought that only a FORM's  name-field can assign a value to a $_POST variable ... ok. should have read more before tryin it all of my own ..

 

here the script (as you can see ... i probably need to learn a lot more to optimize it / or write it a lot shorter ...  :confused: )

 

<?php
session_start('tran');

$_SESSION ['sel_bereich'] = $sel_b;


if (isset($_POST['bereich'])){
   	$_SESSION ['bereich'] = $_POST ['bereich'];
   	if($_POST['sav']){
   		$_SESSION ['choice'] = 'save';
	    }
	else {
	if($_POST['del']){
	    $_SESSION ['areas'] = $_POST ['areas'];
   		$_SESSION ['choice'] = 'delete';
	    }
    }
    header("location:bereiche.php");
}

else { 
   $meldung = "You have to put a value … bla bla … !";
}    
?>


Archived

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

×
×
  • 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.