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
https://forums.phpfreaks.com/topic/260095-help-with-php-multiple-checkboxes/
Share on other sites

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.
So, your not actualy coding your own php, and by that note - why not ask adobe to fix it for you? This is a dreamweaver problem for you, not a php one.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.