Jump to content

help with php multiple checkboxes


wev

Recommended Posts

i  am currently developing a voting system for a school project using dreamweaver..

 

on my vote page, i use checkboxes to select/vote a number of candidates. i want to automatically add/count the total tally and update my database upon submission of votes.

 

since im new to php, all my codes are generated by dreamweaver..and dreamweaver doesn't have a function for handling multiple row update on database.

 

can anyone please help with editing this code to make it work for my system? thanks in advance

 

<?php require_once('Connections/organizazone_db.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tbl_candidates SET votecount=%s WHERE user_id=%s",
                       GetSQLValueString(isset($_POST['vote[]']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['user[]'], "text"));

  mysql_select_db($database_organizazone_db, $organizazone_db);
  $Result1 = mysql_query($updateSQL, $organizazone_db) or die(mysql_error());
}



mysql_select_db($database_organizazone_db, $organizazone_db);
$query_rs_candi = "SELECT * FROM tbl_candidates";
$rs_candi = mysql_query($query_rs_candi, $organizazone_db) or die(mysql_error());
$row_rs_candi = mysql_fetch_assoc($rs_candi);
$totalRows_rs_candi = mysql_num_rows($rs_candi);
$query_rs_candi = "SELECT * FROM tbl_candidates";
$rs_candi = mysql_query($query_rs_candi, $organizazone_db) or die(mysql_error());
$row_rs_candi = mysql_fetch_assoc($rs_candi);
$totalRows_rs_candi = mysql_num_rows($rs_candi);
?>


<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table border="1">
    <tr>
      <td> </td>
      <td>user_id</td>
      <td>votecount</td>
    </tr>
    <?php do { ?>
      <tr>
        <td><input name="vote[]" type="checkbox" id="vote[]" value="1" />
        <label for="vote[]"></label></td>
        <td><label for="user[]"></label>
        <input name="user[]" type="text" id="user[]" value="<?php echo $row_rs_candi['user_id']; ?>" /></td>
        <td><?php echo $row_rs_candi['votecount']; ?></td>
      </tr>
      <?php } while ($row_rs_candi = mysql_fetch_assoc($rs_candi)); ?>
  </table>
<br />
  <br />
<input type="submit" name="submit" id="submit" value="Submit" />
<input type="hidden" name="MM_update" value="form1" />
</form>



<?php
mysql_free_result($rs_candi);
?>

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.