Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2006, 06:59 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating user status with checkbox

Hi everyone!
I need some code help for a problem that i am stuck with. The issue is to update the user table which has a status field which can contain only "YES" or "NO".

My 1st page shows all the listed users with a check box beside them. if the users are active (i.e database contains a "YES" value) then the checkbox are checked otherwise unchecked. If I uncheck any text box that user's value becomes "NO" in the database.

The checkbox looks like:
<input type="checkbox" name="ch<?=$i?>" value="<?=$memdata['adv_id']?>" <?if ($memdata['usr_status']=='YES') {?> checked <?}?>>

** i is the total no. of records
** $memdata['adv_id'] is the user id which is passed through the checkbox

I am using a hidden field to keep the count of check box.
<input type="hidden" name="txtcount" value="<?=$i?>">
** i is the total no. of checkbox & hence the tot. no. of records.


I am using the 2nd page for processing:Here is the code I am using to update the status of the user --

--------------------------------
    if( $_POST['txtcount'] != "" )
    {
        $chcount = $_POST['txtcount'];
    }

    for($i = 0;$i < $chcount; $i++)
    {
        if($_POST['ch'.$i] != "" )
        {
            $up_query = mysql_query("update srch_adv_contact set usr_status = 'YES' where adv_id = '".$_POST['ch'.$i].
                            "'");
        }
        else
        {
            $up_query = mysql_query("update srch_adv_contact set usr_status = 'NO' where adv_id <> '".$_POST['ch'.$i].
                            "'");
        }
    }
--------------------------------------------------------------


With this code if I don't put the else part I can change the status once but I cannot revoke the status again because once I uncheck any of the checkbox no value is updated. With the else clause no status is changed.

Please help me in this situation!!
 
Old February 12th, 2006, 06:02 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check the following for correct syntax...

<input type="checkbox" name="ch<?php echo $i; ?>" value="<?php echo $memdata['adv_id']; ?>"<?php if ($memdata['usr_status']=='YES') { ?>checked<?php } ?>>

<input type="hidden" name="txtcount" value="<?php echo $i; ?>">





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to status of Checkbox of itemcolumn in webpart abjnaveen ASP.NET 1.0 and 1.1 Basics 0 October 17th, 2006 02:57 AM
Gridview Checkbox Update not updating using Access AUhawk ASP.NET 2.0 Basics 0 October 27th, 2005 01:30 AM
Problem displaying User Status from SQL palvin Classic ASP Databases 0 August 2nd, 2005 03:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.