Get HTML form radio button value from MySQL DB, Change and resubmit to DB

I am trying to create a from that gets values from my database.  It has worked fine in the past but I am adding a value to activate and deactivate.  I have these setup for each record in the DB as 1,0 respectively.

I've got the form working correctly to assign the value to the radio button from the value in the DB, However, I cannot update the DB with the changed value if the user selects the opposite radio value.

Here's the form value:
<tr valign="baseline">
          <td nowrap="nowrap" align="right">Active:</td>
          
          <td><input name="payeeActive" type="radio" id="payeeActive" value="1" <?php if ($row_rsPayee['payeeActive'] == "1"){ echo 'checked';} ?>   /> Yes 
          <input name="payeeActive" type="radio" id="payeeActive" value="0" <?php if ($row_rsPayee['payeeActive'] == "0"){ echo 'checked';} ?>/> No
          </td>
        </tr>

Open in new window


Here's the DB UPDATE:
$updateSQL = sprintf("UPDATE tblpayees SET payeeName=%s, payeeAdd=%s, payeeCity=%s, payeeState=%s, payeeZip=%s, payeeAcct=%s, payeeActive=%s WHERE payeeID=%s",
                       GetSQLValueString($_POST['payeeName'], "text"),
                       GetSQLValueString($_POST['payeeAdd'], "text"),
                       GetSQLValueString($_POST['payeeCity'], "text"),
                       GetSQLValueString($_POST['payeeState'], "text"),
                       GetSQLValueString($_POST['payeeZip'], "text"),
                       GetSQLValueString($_POST['payeeAcct'], "text"),
                       GetSQLValueString($_POST['payeeID'], "int"),
					   GetSQLValueString($_POST['payeeActive'], "int"));

Open in new window

LVL 2
axessJoshAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
A few points

HTML elmenets have to have unique ID's - your radio buttons share an id. This is not the cause of  your problem but you should fix it

Try this
$updateSQL = sprintf("UPDATE tblpayees SET payeeName=%s, payeeAdd=%s, payeeCity=%s, payeeState=%s, payeeZip=%s, payeeAcct=%s, payeeActive=%s WHERE payeeID=%s",
                       GetSQLValueString($_POST['payeeName'], "text"),
                       GetSQLValueString($_POST['payeeAdd'], "text"),
                       GetSQLValueString($_POST['payeeCity'], "text"),
                       GetSQLValueString($_POST['payeeState'], "text"),
                       GetSQLValueString($_POST['payeeZip'], "text"),
                       GetSQLValueString($_POST['payeeAcct'], "text"),
                       GetSQLValueString($_POST['payeeActive'], "int"), // This was in the wrong place
                       GetSQLValueString($_POST['payeeID'], "int"));

Open in new window


You put your payeeActive field at the end of the parameter list - so it is being fed into the filter and the payeeID is going to payeeActive
0
Ray PaseurCommented:
Please don't try to learn PHP by reading DreamWeaver code -- it's some of the worst PHP code you can find anywhere.  This is a link to some dependable learning resources.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Radio buttons are like checkboxes.  If they are not fired, they are not present in the request.  This is different from other HTML form input controls which will be present but empty.  You can establish a default value for a radio or checkbox by using a hidden control of the same name immediately before the radio button.  Or you can set and test reasonable default values in your script.
http://www.laprbass.com/RAY_temp_axessjosh.php

<?php // RAY_temp_axessjosh.php
error_reporting(E_ALL);


// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28262035.html
// HOW TO PRESERVE THE VALUE OF RADIO BUTTONS
// EXAMPLE USES THE SESSION, BUT IS APPLICABLE TO THE DB, AS WELL

session_start();

// SET A VALUE FOR THE RADIO, BASED ON WHAT THE SESSION REMEMBERS, OR INITIAL VALUE OF ZERO
$_SESSION['my_radio']
= isset($_SESSION['my_radio'])
? $_SESSION['my_radio']
: 0
;

// SHOW THE REMEMBERED VALUE, OR THE INITIAL VALUE
echo PHP_EOL . "<br>THE REMEMBERED VALUE OF THE RADIO IS {$_SESSION['my_radio']}";


// IF THERE IS A REQUEST
if (!empty($_POST))
{
    // SET THE NEW VALUE IN THE SESSION (OR DATA BASE)
    $_SESSION['my_radio'] = $_POST['my_radio'];
    echo PHP_EOL . "<br>THE CURRENT VALUE OF THE RADIO HAS BEEN SET TO {$_SESSION['my_radio']}";
}

// SET THE FORM VALUES FOR THE RADIO BUTTONS
if ($_SESSION['my_radio'] == 1)
{
    $my_radio_1 = ' checked';
    $my_radio_0 = NULL;
}
else
{
    $my_radio_1 = NULL;
    $my_radio_0 = ' checked';
}

// CREATE THE HTML FORM USING HEREDOC NOTATION
$form = <<<EOD
<form method="post">
<input name="my_radio" type="radio" value="1" $my_radio_1 />Yes
<input name="my_radio" type="radio" value="0" $my_radio_0 />No
<br/>
<input type="submit" />
</form>
EOD;

echo $form;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
@Julian: Yep, that's exactly the sort of thing that happens when people start trying to copy PHP code without understanding the code they are copying.  It seems to afflict Dreamweaver users a lot, but it can happen to anybody who starts Googling for code samples.
0
axessJoshAuthor Commented:
Thansk Ray,

Great help as always.

You are correct, the Dreamweaver code needs to be replaced and I have that on the docket, this was just a hot fix i needed in place for the time being while I rebuild.
0
Ray PaseurCommented:
Thanks for the points and thanks for using EE, ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.