Jump to content

wev

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Posts posted by wev

  1. 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);
    ?>
    

  2. im developing a voting system where you can vote for multiple choices using checkboxes..

    upon submitting the vote form, votecounts must automatically be updated.. values for votecount will come from the checkbox value 1.

     

     

    ive been having a hard time trying to figure out hot to update multiple rows with checkbox values..any help would be appreciated..thanks in advance!

     

    here's the code:

     

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    
    if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form_vote"))
    $i=1;{
    while ($i<= $totalRows_rs_candi) {
      $updateSQL = "UPDATE tbl_candidates SET votecount={$_POST['votecount']} WHERE user_id={$_POST['candi']}";
    
      mysql_select_db($database_organizazone_db, $organizazone_db);
      $Result1 = mysql_query($updateSQL, $organizazone_db) or die(mysql_error());
      
      $i++;
    }
    
      if (isset($_SERVER['QUERY_STRING'])) {
      $updateGoTo = "vote_success.php";
      }
      header(sprintf("Location: %s", $updateGoTo));
    }

     

     

    <form id="form_vote" name="form_vote" method="POST" action="<?php echo $editFormAction; ?>">
      <table border="1">
        <tr>
          <td> </td>
          <td>user_id</td>
          <td>l_name</td>
          <td>course_id</td>
          <td>yearlevel</td>
          <td>about</td>
        </tr>
        <?php $i=1; do { ?>
          <tr>
            <td><span id="sprycheckbox1">
            <input name="votecount[<?php echo $i ?>]" type="checkbox" id="votecount" value="1" />
            <span class="checkboxMinSelectionsMsg">Minimum number of selections not met.</span></span>          
            <label for="votecount[]"></label></td>
            <td><label for="candi"></label>
            <input name="candi" type="text" disabled="disabled" id="candi" value="<?php echo $row_rs_candi['user_id']; ?>" readonly="readonly" /></td>
            <td><?php echo $row_rs_candi['l_name'].' ,'.$row_rs_candi['f_name'].' '.$row_rs_candi['m_name']; ?></td>
            <td><?php echo $row_rs_candi['course_id']; ?></td>
            <td><?php echo $row_rs_candi['yearlevel']; ?></td>
            <td><?php echo $row_rs_candi['about_me']; ?></td>
          </tr>
          <?php $i++; ?>
          <?php } while ($row_rs_candi = mysql_fetch_assoc($rs_candi)); ?>
      </table>

  3. here i am again...

     

    so i have this algorithm that computes the current academic year for our school..

    it outputs the correct academic year on a browser..

    but when i try to insert it into my database, the data inserted goes wrong..

     

    it just keeps on inserting -1 instead of the string 2011-2012

     

    here's my code:

    <?php
    
    $year = date('Y');
    $currentyear = $year;
    $lastyear = $year - 1;
    $nextyear = $year + 1;
    
    if (date('m') < 6)
    {
     $current_ay = $lastyear."-".$currentyear;
    }
    else
    if (date('m') >= 6)
    {
     $current_ay = $currentyear."-".$nextyear;
    }
    
    echo $current_ay;
      $insertSQL = "INSERT INTO tbl_elections (election_id) values ($current_ay)";
    
      mysql_select_db($database_organizazone_db, $organizazone_db);
      $Result1 = mysql_query($insertSQL, $organizazone_db) or die(mysql_error());
    
    ?>

     

     

    *the database column to be inserted into is of varchar data type

     

  4. hi there..im new to php mysql and im having trouble inserting a string data to mysql from a php date() function.

     

     

    here's my code:

     $year = date('Y');
    echo $year;
      $insertSQL = sprintf("INSERT INTO tbl_elections (election_id=$year)");
    
      mysql_select_db($database_organizazone_db, $organizazone_db);
      $Result1 = mysql_query($insertSQL, $organizazone_db) or die(mysql_error());

     

    when i try to output the $year variable on a webpage, it returns "2012"

    but when i try to insert this data into my database table, it returns an error like this:

     

    check the manual that corresponds to your MySQL server version for the right syntax to use near '=2012)'

     

    is there a way to convert "2012" into a normal string data type?

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