Page 1 of 3

[SOLVED] checkbox value

Posted: Tue Aug 17, 2004 4:15 am
by g3ckO
check this code:

Code: Select all

<?php
session_start(); 
include("database.php");


   $user=addslashes($_SESSION[username]);
 
   $query="SELECT * FROM `leave` a INNER JOIN `employee` b ON b.`StaffNo` = a.`Super` WHERE b.`username` = '$user'AND a.`Status` = 'Pending 

Review'";
 
   $result=mysql_query($query) or die(mysql_error());

?>	   
	<div align="left">
   	<table border="0" cellpadding="2" cellspacing="1" width="100%">
    	<tr>
        <td align="left" valign="bottom" width="2%"
            bgcolor="lightskyblue" valign="TOP" marginwidth="12" marginheight="12">
          
        </td>
        <td align="left" valign="bottom" width="25%"
            bgcolor="lightskyblue" valign="TOP" marginwidth="12" marginheight="12">
          
            <b>NAMA</b>
        </td>
   	<td align="left" valign="top" width="18%"
            bgcolor="lightskyblue" marginwidth="12" marginheight="12">
	    
            <b>REF. ID</b>
        </td>
   	<td align="left" valign="top" width="17%"
            bgcolor="lightskyblue" marginwidth="12" marginheight="12">
	    
            <b>TARIKH PERMOHONAN</b>
        </td>
   	<td align="left" valign="top" width="20%"
            bgcolor="lightskyblue" marginwidth="12" marginheight="12">
	    
            <b>TARIKH CUTI</b>
        </td>
   	<td align="left" valign="top" width="18%"
            bgcolor="lightskyblue" marginwidth="12" marginheight="12">
	    
            <b>STATUS</b>
        </td>
    	</tr>
   	</table>
   	</div>

<?

   while ($row = mysql_fetch_array($result))

	{


   	$refid=$row["RefID"];
   	$nama = $row["Nama"];
   	$jawatan = $row["Jawatan"];
  	$jenis = $row["Jenis"];
  	$mula = $row["DateMula"];
   	$tamat = $row["DateTamat"];
   	$mohon = $row["DateMohon"];
   	$refid = $row["RefID"];
   	$status = $row["Status"];      
	
  	$access = $row["AccType"]; 
   	$ack_by = $row["EmpName"];

        echo"<form action=leave_app_2.php?$approved method=POST>";
	
?>
	
	<div align="left">
   	<table border="0" cellpadding="2" cellspacing="1" width="100%">
    	<tr>
        <td align="left" valign="bottom" width="2%"
            bgcolor="lightskyblue" valign="TOP" marginwidth="12" marginheight="12">
          
            <?echo"<input type=checkbox name=approved[] value=$refid>";?>
        </td>
        <td align="left" valign="bottom" width="25%"
            bgcolor="lightskyblue" valign="TOP" marginwidth="12" marginheight="12">
          
            <?echo"$nama";?>
        </td>
   	<td align="left" valign="top" width="18%"
            bgcolor="lightskyblue" marginwidth="12" marginheight="12">
	    
            <?echo"$refid";?>
        </td>
   	<td align="left" valign="top" width="17%"
            bgcolor="lightskyblue" marginwidth="12" marginheight="12">
	    
            <?echo"$mohon";?>
        </td>
   	<td align="left" valign="top" width="20%"
            bgcolor="lightskyblue" marginwidth="12" marginheight="12">
	    
            <?echo"$mula";?> hingga <?echo"$tamat"?>
        </td>
   	<td align="left" valign="top" width="18%"
            bgcolor="lightskyblue" marginwidth="12" marginheight="12">
	    
            <?echo"$status";?>
        </td>
    	</tr>
   	</table>
   	</div>
<?
	}
?>

	<input type="hidden" name="statusby" value="<? echo $ack_by; ?>" >

	<br>
	<div align="left">
   	<table width="100%">
    	<tr>
        <td align="right" width="50%">
                    
   	<input type="submit" value="APPROVED" name="app">            
        </td>
        <td align="left" width="50%">
             
   	<input type="submit" value="NOT APPROVED" name="notapp">
        </td>
    	</tr>
   	</table>
   	</div>
	</form> 

?>
I got the display like I want it to be.. But now how to pass the value of the checkbox.

When the approved button is clicked. I want the value of status in table leave to change from pending review to approved.

When the not approved button is clicked. I want the value of status in table leave to change from pending review to not approved.

Just want to know what variable should I pass to the update query to update data in table leave?

Posted: Tue Aug 17, 2004 10:17 am
by feyd
flip it off of $_POST['app']/$_POST['notapp'] ... just be aware that neither will exist if the person hit enter to submit it from a field..

[edit: removed double negative]

Posted: Tue Aug 17, 2004 9:25 pm
by g3ckO
Is the query code like this?

Code: Select all

<?php
session_start(); 
include("database.php");

global $conn;

$statusby = $_POST['statusby'];

if ($_POST['app'])
   {
	$query = UPDATE leave SET
	Status = 'Approved', StatusBy = '$statusby'
	WHERE

                mysql_query($query, $conn); 
   }

if($_POST['notapp'])
   {
	$query = UPDATE leave SET
	Status = 'Not Approved', StatusBy = '$statusby'
	WHERE

                mysql_query($query, $conn);
   }
?>
What should I put in the WHERE??

WHERE is for the checked checkbox.

Posted: Tue Aug 17, 2004 9:33 pm
by feyd
the id number of it..

Posted: Tue Aug 17, 2004 9:39 pm
by g3ckO
the id number of it..
Don't get it... :roll:

Posted: Tue Aug 17, 2004 9:40 pm
by tim
$refid = $row["RefID"];

Posted: Tue Aug 17, 2004 9:45 pm
by feyd
$_POST['approved'][X] actually..

Posted: Tue Aug 17, 2004 10:06 pm
by g3ckO

Code: Select all

<?php<?

session_start(); 
include("database.php");

global $conn;

$statusby = $_POST['statusby'];

if ($_POST['app'])
   {
	$query = UPDATE leave SET
	Status = 'Approved', StatusBy = '$statusby'
	WHERE $refid = $row["RefID"];

	mysql_query($query, $conn);
   }

if($_POST['notapp'])
   {
	$query = UPDATE leave SET
	Status = 'Not Approved', StatusBy = '$statusby'
	WHERE $refid = $row["RefID"];

	mysql_query($query, $conn);
   }

?> 

?>
Error message> Parse error: parse error, unexpected T_STRING in c:\apache\htdocs\leave_app_2.php on line 12.

??

Posted: Tue Aug 17, 2004 10:10 pm
by feyd
you kinda need to put the sql string into an actual string...

Posted: Tue Aug 17, 2004 10:22 pm
by g3ckO

Code: Select all

<?php

<?

session_start(); 
include("database.php");

global $conn;

$statusby = $_POST['statusby'];

if ($_POST['app'])
   {
	$query = "UPDATE leave SET
	Status = 'Approved', StatusBy = '$statusby'
	WHERE $refid = $row["RefID"]";

	mysql_query($query, $conn);
   }

if($_POST['notapp'])
   {
	$query = "UPDATE leave SET
	Status = 'Not Approved', StatusBy = '$statusby'
	WHERE $refid = $row["RefID"]";

	mysql_query($query, $conn);
   }

?> 
?>
Parse error: parse error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\apache\htdocs\leave_app_2.php on line 14

Posted: Tue Aug 17, 2004 10:56 pm
by feyd
look at the highlighted code of your post there.. you should see what's wrong..


hint: the string syntax needs a few escapes for the variables..

Posted: Tue Aug 17, 2004 11:00 pm
by g3ckO
hmm.. how should I write it??

Code: Select all

<?php
	$query = "UPDATE leave SET
	Status = 'Approved', StatusBy = '$statusby'
	WHERE $refid = $row['RefID']";

?>
also get error..

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\apache\htdocs\leave_app_2.php on line 14

Posted: Tue Aug 17, 2004 11:10 pm
by feyd
RefID = {$row['RefID']}

although that assumes you have $row['RefID'] set on the processing script's end..

Posted: Tue Aug 17, 2004 11:21 pm
by g3ckO

Code: Select all

<?php
session_start(); 
include("database.php");

global $conn;

$statusby = $_POST['statusby'];

if ($_POST['app'])
   {
	$query = "UPDATE leave SET
	Status = 'Approved', StatusBy = '$statusby'
	WHERE RefID = {$row['RefID']}";

	mysql_query($query, $conn);
   }

if($_POST['notapp'])
   {
	$query = "UPDATE leave SET
	Status = 'Not Approved', StatusBy = '$statusby'
	WHERE RefID = {$row['RefID']}";

	mysql_query($query, $conn);
   }
?>
No error but the data in database is not update...

headache already... :?

Posted: Tue Aug 17, 2004 11:27 pm
by feyd
$row['RefID'] probably isn't set... need to pull it from the posted data... should be inside $_POST['approved']

print_r($_POST['approved']) to look at the data