<?php
include "connection.php";
if(!isset($_SESSION))
{
session_start();
}
$cand1 = $_POST['cand1'];
$cand2 = $_POST['vice1'];
$sess = $_SESSION['SESS_NAME'];
if(!$cand1){
$error="<center><h4><font color='#FF0000'>Please fill empty fields</h4></center></font>";
include"student.php";
exit();
}
$cand1 = addslashes($cand1);
$cand1 = mysqli_real_escape_string($con,$cand1);
$sql = 'SELECT * FROM student WHERE username="'.$_SESSION['SESS_NAME'].'" AND status="VOTED"';
$result = mysqli_query($con,$sql);
if (mysqli_num_rows($result)==1){
$msg="<center><h4><font color='#FF0000'>You have already been voted, No need to vote again</h4></center></font>";
include 'student.php';
exit();
}
else{
$sql = 'UPDATE candidate SET votecount = votecount + 1 WHERE cand_id = "'.$_POST['cand1'].'" OR cand_id = "'.$_POST['vice1'].'"';
$sql2 = 'UPDATE student SET status="VOTED" WHERE username="'.$_SESSION['SESS_NAME'].'"';
$result = mysqli_query($con,$sql);
$result2 = mysqli_query($con,$sql2);
if(!$result && !$result2){
die("Error on mysql query".mysqli_error());
}
else{
$msg="<center><h4><font color='#FF0000'>Congratulation, you have made your vote.</h4></center></font>";
include 'student.php';
exit();
}
}
?>
エラーが $のSES = $ _SESSION [ 'SESS_NAME']を含むコードです。そして、username = "'。$ _ SESSION [' SESS_NAME ']。'" 私はすべての可能性を試したので、私のコードをチェックできますか? $ session [session_name]のエラーは主にエラーです。注意:未定義のインデックス:行にstudent_vote.phpでSESS_NAME 9
存在しない '$ _SESSION'の変数にアクセスしようとしています。 'student_vote.php'につながるコードに' $ _SESSION ['SESSION_NAME'] 'を設定していますか?あなたは[docs](http://php.net/manual/en/function.session-name.php)のセッションの設定方法について読むことができます –
[PHP: "Notice:Undefined variable"、 "通知:未定義インデックス "と"通知:未定義オフセット "](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) –
うんおそらく –