Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

UPDATE Record in MYSQL DB using PHP / Radio Button

im tyring to update a records data by selecting a radio.

i have a records data displayed in a table and in last column of table, there is a radio button.

if user selects radio button, update mysql db, setting some fields value = 0.

requiring help.

anybody wish to give it a shot with me?

have alot of it coded already, but with some minor errors
ASKER CERTIFIED SOLUTION
Avatar of Diablo84
Diablo84

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ellandrd

ASKER

well what im trying to do is update a properties status. there is no submit button, just a radio button beside the propertys details.

first i display the properties details with a radio button at the end in the last column. if user clicks radio button update the selected properties details in the db. the field that gets updated is called 'property_featured'

when updated its value is set 0 so it doesnt show in the featured list. by defualt it is set to 1 so it does show in the featured list.

here is my code so far:


<?php
require("includes/session.inc.php");
require("includes/db.inc.php");
$link_id = db_connect();

if (isset($_POST['property_featured']))
{
  $idno = (isset($_POST["id"]) && !empty($_POST["id"])) ? trim($_POST["id"]) : "";
  $query = "UPDATE tblProperties SET property_featured = 0 WHERE record_id={$idno}";
  mysql_query($query, $link_id) or die("problems!</body></html>");
}

$query = "SELECT * FROM tblProperties WHERE property_featured = 1";
$propertyResult = mysql_query($query, $link_id) or die("Problems!!</body></html>");
?>
<html>
<head></head>
<title></title>
<script language="JavaScript">
<!--
bAllowSubmit = true;
function SubmitForm(obj, uid)
{
      if (bAllowSubmit == true)
      {
            bAllowSubmit = false;

            document.HiddenForm.HiddenField.name = obj.name;

            if (obj.checked == true)
            {
                  document.HiddenForm.HiddenField.value = 1;
            }
            else
            {
                  document.HiddenForm.HiddenField.value = 0;
            }
            document.HiddenForm.UniqueID.value = uid;
            document.HiddenForm.submit();
      }
}
//-->
</script>
<body>
<form name="HiddenForm" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
     <input type="hidden" id="HiddenField" name="" value="">
     <input type="hidden" id="UniqueID" name="id" value="">
</form>
<table width="100%">
<tr>
      <td>property_ref_num</td>
      <td>property_name_number</td>
      <td>property_street</td>
      <td>property_town_city</td>
      <td>property_price_type</td>
      <td>property_price</td>
</tr>

<?php
while ($aRow = mysql_fetch_array($propertyResult)) !== False)
{
      ?>
      <tr>
            <td><?php echo $aRow['property_ref_num'];?></td>
            <td><?php echo $aRow['property_name_number'];?></td>
            <td><?php echo $aRow['property_street'];?></td>
            <td><?php echo $aRow['property_town_city'];?></td>
            <td><?php echo $aRow['property_price_type'];?></td>
            <td><?php echo $aRow['property_price'];?></td>

            <form name="myform">
            <td><input type="radio" name="property_featured" value=0 onClick="SubmitForm(this, <?php echo $aRow['record_id'];?>);"></td>
            </form>

      </tr>
      <?php
}
?>
</table>
</body>
</html>

but dont work... no errors
oh it just worked! a few mins ago, nothing happened..

right thats that working.

i have another question to ask but i'll accept this one first and open another 1 for the second part of this question...

look out for a question called "PART 2 - UPDATE Record in MYSQL DB using PHP / Radio Button"

Ellandrd
Avatar of Diablo84
Diablo84

What doesn't work exactly, does the script function but the update query does not correctly run?

On first glance i would replace:

while ($aRow = mysql_fetch_array($propertyResult)) !== False)
{

with:

while ($aRow = mysql_fetch_assoc($propertyResult)) {

Checking rest of script now.

Diablo84
oh ok, will do :)

Diablo84