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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 … !";
}    
?>


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.