为什么它不是';t节省一年时间


What are the reasons why it isn't saving the year?

sample我在输入school_year(syearid)时遇到问题。我必须把年份自动放在vote.php中,该怎么办?我这样做对吗?这是我的数据结构图。看起来像

这是我的代码:

$idnum=$_POST['idnum'];
$stat='voted';
$sqla = "UPDATE student 
    SET status=?
    WHERE idno=?";
$qa = $db->prepare($sqla);
$qa->execute(array($stat,$idnum));
$edittable=$_POST['votes'];
$a=1;
$N = count($edittable);
$YearNow=Date('Y');
//making an option 
echo '<label class="control-label col-md-7 col-sm-3 col-xs-12">School Year</label>';
echo '<select  name="syearid" class="select2_group form-control"  style="text-align:center;" >';
echo'<optgroup label="School Year" style="text-align:center;">';
echo '<?php';
date("Y");
include('../connection/connect.php');
$result = $db->prepare("SELECT * FROM school_year");
$result->bindParam(':syearid', $res);
$result->execute();
for ($i=0; $row = $result->fetch(); $i++) {
    $isSelected = ((date("Y") == $row['from_year']) ? " selected" : "");
    echo "<option value='".$row['syearid']."'$isSelected>".$row['from_year'].'-'.$row['to_year']."</option>";
    echo'?>';
    echo'</optgroup>';
    echo'</select>';
    for($i=0; $i < $N; $i++)
    {
        $sql = "UPDATE candidates,student,school_year 
            SET votes=votes+?
            WHERE candid =? AND school_year.syearid = candidates.syearid  AND school_year.from_year like $YearNow  ";
        $q = $db->prepare($sql);
        $q->execute(array($a,$edittable[$i]));      
        $sqlas = "INSERT INTO studentvotes(candid,idno,syearid) VALUES (:m,:n,:o)";
        $qs = $db->prepare($sqlas);
        //this is where my problem is how to put the selected year in another mysql?
        $qs->execute(array(':m'=>$edittable[$i],':n'=>$idnum,':o'=>$isSelected));
    }
}
header("location: notification.php?". http_build_query($query));
mysql_close($con);
?>

您正试图在syearid字段中插入一个字符串("选定"或空字符串)。

...
$isSelected = ((date("Y") == $row['from_year']) ? " selected" : "");
...
$sqlas = "INSERT INTO studentvotes(candid,idno,syearid) VALUES (:m,:n,:o)";
...
$qs->execute(array(':m'=>$edittable[$i],':n'=>$idnum,':o'=>$isSelected));

我想,传递的值应该是INTDATE的类型(取决于字段类型)