Jump to content

UPDATE table with array when submit


jacko_162

Recommended Posts

I have the below code:

 

<div>
				  <table width="100%" border="0" cellspacing="0" cellpadding="4">
                            <tr>
                              <td colspan="7" valign="top">
                              <form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<?php
if (isset($submit)) {
  // UPDATE QUERY CODE WHEN SUBMIT IS ENTERED
$str = implode(';',$_POST['checks']);
$insert = "UPDATE members SET
settings='$str'
WHERE member_id='$_SESSION[sESS_MEMBER_ID]'";

if (@mysql_query($insert))
{
?>
                          <script type="text/javascript">
document.location.replace('settings-tests.php');
                          </script>
                          <?php
}
else {
echo('Error in you submission:' . mysql_error() . "<br /><br />" . $sql);
}
}
?>
                          <?php
  {
  
    $result=mysql_query("SELECT * FROM members WHERE member_id = '$_SESSION[sESS_MEMBER_ID]'");
    $row = mysql_fetch_array($result);
    $arr = array();
    $arr = explode(';',$row['settings']);
    $member_id = $row['member_id'];
    $firstname = $row['firstname'];
    $lastname = $row['lastname'];
    $email = $row['email'];
    $membership = $row['membership'];
    $roles = $row['roles'];
    $login = $row['login'];

    ?>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
  <tr>
    <td colspan="2"><h3>Test Results Settings</h3></td>
    <td width="25%"> </td>
    <td width="25%"><?php
echo $_SESSION['SESS_MEMBER_ID'];
?></td>
  </tr>
  <tr>
    <td colspan="4"><em>To turn off individual results gloablly across the site please use the following sliders (all results already added will also be made invisable)<br />
      <br />
    </em></td>
    </tr>
  <tr>
    <td width="25%"><div align='right'><strong><em>Salinity:</em></strong></div></td>
    <td width="25%"><input type="checkbox" value="test1" name="checks[]2" <?php echo (in_array("test1",$arr) ? "checked" : ''); ?>/></td>
    <td><div align='right'><strong><em>Phosphate:</em></strong></div></td>
    <td><input type="checkbox" value="test9" name="checks[]10" <?php echo (in_array("test9",$arr) ? "checked" : ''); ?>/></td>
  </tr>
  <tr>
    <td><div align='right'><strong><em>PH:</em></strong></div></td>
    <td><input type="checkbox" value="test2" name="checks[]3" <?php echo (in_array("test2",$arr) ? "checked" : ''); ?>/></td>
    <td><div align='right'><strong><em>potassium:</em></strong></div></td>
    <td><input type="checkbox" value="test10" name="checks[]11" <?php echo (in_array("test10",$arr) ? "checked" : ''); ?>/></td>
  </tr>
  <tr>
    <td><div align='right'><strong><em>Ammonia:</em></strong></div></td>
    <td><input type="checkbox" value="test3" name="checks[]4" <?php echo (in_array("test3",$arr) ? "checked" : ''); ?>/></td>
    <td><div align='right'><strong><em>Iodine:</em></strong></div></td>
    <td><input type="checkbox" value="test11" name="checks[]12" <?php echo (in_array("test11",$arr) ? "checked" : ''); ?>/></td>
  </tr>
  <tr>
    <td><div align='right'><strong><em>Nitrite:</em></strong></div></td>
    <td><input type="checkbox" value="test4" name="checks[]5" <?php echo (in_array("test4",$arr) ? "checked" : ''); ?>/></td>
    <td><div align='right'><strong><em>Strontium:</em></strong></div></td>
    <td><input type="checkbox" value="test12" name="checks[]13" <?php echo (in_array("test12",$arr) ? "checked" : ''); ?>/></td>
  </tr>
  <tr>
    <td><div align='right'><strong><em>Nitrate:</em></strong></div></td>
    <td><input type="checkbox" value="test5" name="checks[]6" <?php echo (in_array("test5",$arr) ? "checked" : ''); ?>/></td>
    <td><div align='right'><strong><em>Silica:</em></strong></div></td>
    <td><input type="checkbox" value="test13" name="checks[]14" <?php echo (in_array("test13",$arr) ? "checked" : ''); ?>/></td>
  </tr>
  <tr>
    <td><div align='right'><strong><em>Calcium:</em></strong></div></td>
    <td><input type="checkbox" value="test6" name="checks[]7" <?php echo (in_array("test6",$arr) ? "checked" : ''); ?>/></td>
    <td><div align='right'><strong><em>Temperature:</em></strong></div></td>
    <td><input type="checkbox" value="test14" name="checks[]" <?php echo (in_array("test14",$arr) ? "checked" : ''); ?>/></td>
  </tr>
  <tr>
    <td><div align='right'><strong><em>Magnesium:</em></strong></div></td>
    <td><input type="checkbox" value="test7" name="checks[]8" <?php echo (in_array("test7",$arr) ? "checked" : ''); ?>/></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td><div align='right'><strong><em>Alkalinity:</em></strong></div></td>
    <td><input type="checkbox" value="test8" name="checks[]9" <?php echo (in_array("test8",$arr) ? "checked" : ''); ?>/></td>
    <td colspan="2" align="right"></td>
    </tr>
  <tr>
    <td colspan="4" align="right"><table border="0" cellspacing="0" cellpadding="8">
      <tr>
        <td><input class="Button" type="submit" name="submit" value="Submit" /></td>
      <td><input class="Button-alt" type="reset" name="reset" value="Reset" /></td>
    </tr>
    </table></td>
    </tr>
</table>

                                    
							<br />

				  </form><?php
}
?>                              </td>
                        </tr>
                      </table>
				</p>
			  </div>

 

This pulls data in array from database for example:

 

test1;test9;test2;test3;test4;test5;test6;test14;test7;test8

 

The SELECT query works fine if i manually edit the array in the database to make the boxes checked or not.

 

Problem seems to be when i click submit, its not updating the DATABASE?!

 

i recently upgraded to PHP5 eventually and it seems it stopped working arond then.

 

any help please.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.