[SOLVED] checkbox value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not sure which field you need to update so they move into the approved status.. so uh...

well.. it should only need some changes to the 'foo' line..
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

I need to update the field status from table leave.

So when the user clicked the Approved button.. the value of status will change from Pending Review to Approved.

When the user clicked the Not Approved button.. the value of status will change from Pending Review to Not Approved.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

k.. so then it'd be something like:

Code: Select all

<?

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

global $conn;

$statusby = $_POST['statusby'];

if(isset($_POST['app']))
{

   $sql = 'UPDATE leave SET ';
   $sql .= 'status = ''Approved'' '; 
   $sql .= 'WHERE RefID IN(''' . implode(''',''', $_POST['approved']) . ''')';


   mysql_query($query, $conn);
}
elseif(isset($_POST['notapp']))
{  // not approved clicked..

   $sql = 'UPDATE leave SET ';
   $sql .= 'status = ''Not Approved'' '; 
   $sql .= 'WHERE RefID IN(''' . implode(''',''', $_POST['approved']) . ''')';


   mysql_query($query, $conn);}
else
{  // in case someone hits enter for the submittal...
  die('YOU MUST SELECT EITHER <b>APPROVED</b> OR <b>NOT APPROVED</b>.');
}
?>
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

When I don't checked any checkbox and clicked the approved button I got this error:
Warning: implode(): Bad arguments. in c:\apache\htdocs\leave_app_2.php on line 15

But when I checked the checkbox, I don't get any error message but the status in database still not change.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I warned you that you'll need to add some checks for an empty set of checkboxes...

As for it not updating, it may have an error in the syntax (depending on the RefID being right or not) adding "or die(mysql_error())" to each mysql_query call would tell you if there's a syntax error..
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

feyd wrote:I warned you that you'll need to add some checks for an empty set of checkboxes...
:lol: I will do the check later..

The data not updating coz it say the Query was empty. But why??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

switch $query for $sql
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

Okay².... its work now..

Thank you very² much feyd...

~feyd.. the real guru.. :)
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

one more question.. simple one I think.. :)

Code: Select all

<?php
$sql .= 'Status = ''Approved'' ,StatusBy = ''$statusby'' ';
?>
It update Statusby field to $statusby in database, not the value of $statusby.

I want the value of $statusby to be update to database.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$sql .= 'Status = ''Approved'' ,StatusBy = ''' . $statusby . ''' ';
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

Problem solved..
Post Reply