hello,
i learned recently how to use hidden variables, and its features. but i have some problems when i use more than 3 values :S

this is a portion of the code:

<?php
$hidden = $_POST['action']; 
 if ($hidden==0) //present the form, note the value of hidden 
 { 
   ?>		
 <form action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr align="center"> 
  <td colspan="2"><input name="update" type="submit" value="Update User Data"></td>
   <td colspan="2"><input name="delete" type="submit" value="Delete User"></td>
</tr> 
 <input type="hidden" name="action" value="1">
</table>
</form>
	
<!-- here is the delete section -->  	
<?php 
    }    
   if ($hidden==1) // so the delete button is pressed
   {  
      include 'config.php';
      include 'opendb.php';
     
      $query = "DELETE FROM user WHERE Id = '$ID'";
      mysql_query($query) or die('Error, query failed');
      
      include 'closedb.php';
   ?> 
    This user is deleted!!<br /> 
    <form action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post"> 
       <input type="hidden" name="action" value="0"> 
       <a href="registered.php">Back to registered users page</a>
    </form> 
  <?php  
  } 
 
  if ($hidden==2) // so the update button is pressed
   {  
     // some code here
   ?> 
  This user is updated!!<br /> 
  <form action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post"> 
  <input type="hidden" name="hidden" value="0"> 
  
  </form> 
 <?php  
 }   
 ?>

in this way only the initial form and the delete work
so how could i set the hidden value to 2 :S
help !

Yeah. This is just a simple example how you can assign a value to a field.

<html>
<body>
<form method="post" name="hidden" action="hidden.php">
<input type="text" name="action">
<input type="button" name="button" value="Update" onclick="javascript: document.hidden.action.value='1';">
<input type="button" name="button" value="Delete" onclick="javascript: document.hidden.action.value='2';">
</form>
</body>
</html>

so what will be in the "hidden.php" file ??

and how could i use switch case to handle this issue
value 0 : the form
value 1: Delete
value 2: update

i tried to do it, but i couldn't :(

thx
zanzo

<?php //this script is hidden.php
$action=$_POST['action'];
echo $action; //use $action in your switch case
?>
<html>
<body>
<form method="post" name="hidden" action="hidden.php">
<input type="hidden" name="action">
<input type="button" name="button" value="Update" onclick="javascript: document.hidden.action.value='1';document.hidden.submit();">
<input type="button" name="button" value="Delete" onclick="javascript: document.hidden.action.value='2';document.hidden.submit();">
</form>
</body>
</html>

actually i have problems with the switch case
it does never work :(

<html>
<body>
<form method="post" name="hidden" action="test.php">
<input type="hidden" name="action" value = "0">
<?php 

$action=$_POST['action'];
switch($action){
case "1": echo ($action); 
?>
<input type="button" name="button" value="Update" onclick="javascript<b></b>: document.test.action.value='1';document.test.submit();">
<?php break;
	case "2": echo ($action);?> 
<input type="button" name="button" value="Delete" onclick="javascript<b></b>: document.test.action.value='2';document.test.submit();">
<?php break;
	default: echo ($action);break;
	}?>
</form>

</body>
</html>

There is something wrong here :(

Umm..What exactly are you trying to do ?

in the Details.php page:
i have the detailed information about a certain user (in non editable way)
then, 2 buttons one for delete and other for update

delete: will delete all user info in the database
update: will open a boxes that contain user info but in editable way to in order to update

then in this same page (Details.php), i tried to use hidden variable:

<?php     $hid = $_POST['action']; 
     if ($hid==0) //present the form, note the value of hidden 
    { 
?>		
 <form action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post">
 <table>
 <tr align="center"> 
 <td colspan="2"><input name="update" type="submit" value="Update User Data"></td>
 <td colspan="2"><input name="delete" type="submit" value="Delete User"></td>
 </tr> 
  <input type="hidden" name="action" value="1">
</table>
</form>
	
<!-- here is the delete section -->  	
<?php 
    }     
   if ($hid==1) // so the delete button is pressed
   {  
     // code to delete user info
   ?> 
    This user is deleted!!<br /> 
    <form action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post"> 
       <input type="hidden" name="action" value="0"> 
    </form> 
  
<!-- here is the update section -->
<?php  
  }  
   if ($hid==2) // so the update button is pressed
   {  
    // code to update user info
   ?> 
  This user is updated!!<br /> 
  <form action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post"> 
  <input type="hidden" name="hidden" value="0">   
  </form> 
 
<?php  
 }   
   ?>

this code will work, in case i did not put the update section
where in the first form i put the value=1 => which implies the Delete button true
if if put value=2 => the update will work but the delete will not

so i've tried to use switch case, but it doesn't work
so i don't know what to do :(

I tried the following code, but also it doesn't work :(

<html>
<body>

<?php 
$i = $_POST['action'];

switch ($i) {
case 0:
    echo "i equals 0";
    ?><form action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post">
		<table>
			<tr align="center"> 
        <td colspan="2"><input name="update" type="submit" value="Update User Data"></td>                   
        <td colspan="2"><input name="delete" type="submit" value="Delete User"></td>
        <input type="hidden" name="action" value="2">
      </tr>             
		</table>
		</form><?php
    break;
case 1:
    echo "i equals 1";
    echo "This user is deleted";  
    ?>
    <form action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post"> 
  <input type="hidden" name="upd" value="0"> 
  
  </form> <?php
    break;
case 2:
    echo "i equals 2";
    echo "This user is updated";
    ?>
    <form action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post"> 
    <input type="hidden" name="upd" value="0"> 
  
  </form> <?php
    break;
}
?>

</body>
</html>

Why do you need a switch when you know $_POST can only have 2 values. Either 1 or 2. You can make use of a simple if condition.

$action = $_POST['action'];
if($action == 1 ) {
 // show the textboxes and update 
}
if($action == 2 ){
 // delete the record
}

and so where would i put

<input type="hidden" name="action" value="1">

and how it will change of value :S

I would suggest you to go through the tutorials first. Then understand the example I gave you.

well i done with it
thx for advice
this is the code

if ($action==0) //present the form
    {     
	    ?>		
		<form name="updateform" action = "update.php?ID=<?php echo $ID; ?>" method="post">
      <input type="hidden" name="action" value="update">
      <input name="update" type="submit" value="Update User Data">
		</form>
	
		<form name="deleteform" action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post">	
      <input type="hidden" name="action" value="delete">
      <input name="delete" id="delete" type="submit" value="Delete User" onClick=" return checkDelete();">
		</form>
	
	<!-- here is the delete section -->  	
		<?php 
   } 
    
   if ($action=="delete") // so the delete button is pressed
   {     	     
    /* include 'config.php';
      include 'opendb.php';
     
      $query = "DELETE FROM user WHERE Id = '$ID'";
      mysql_query($query) or die('Error, query failed');
      
      include 'closedb.php';*/
   	echo("This user info is deleted ");
   ?> 
   <a href="registered.php">Back to registered users page</a>   
    <? }?>

but i do still have small problem where when the user click "delete" the update & delete buttons will still appear in the page :s who could i remove them??
regards

<?php
if ($action==0) //present the form
    {     
?>		
<form name="updateform" action = "update.php?ID=<?php echo $ID; ?>" method="post">
      <input type="hidden" name="action" value="update">
      <input name="update" type="submit" value="Update User Data">
</form>
	
<form name="deleteform" action = "<? echo $_SERVER['PHP_SELF']; ?>" method="post">
      <input type="hidden" name="action" value="delete">
      <input name="delete" id="delete" type="submit" value="Delete User" onClick=" return checkDelete();">
</form>
	
<!-- here is the delete section -->  	
<?php 
   }     
   if ($action=="delete") // so the delete button is pressed
   {     	     
   // code to delete
   echo("This user info is deleted ");
   ?> 
   <a href="registered.php">Back to registered users page</a>   
    <? }
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.