vendredi 30 juin 2017

Check if table row is equal to week value then execute insert query

please i want to learn how to implement a query... i am designing a report system, i want each users to be able to submit reports to their upline boss once a week.

So, i want to check if the week of the last submitted report of a particular user is not equal to present week, then execute and submit report if it equals then echo warning message... here is my code below:

<?php
require('connect.php');
require('session.php');
$ddate = date("Y-m-d");
$date = new DateTime($ddate);
$week = $date->format("W");
$query= "SELECT * FROM memberTable, reportTable where user_id = '$session_id'";
$result = $DBcon->query($query);
$row3 = $result->fetch_assoc();

$submitted = "";
$status = "";
if(isset($_POST['btnsendreport'])){
    $created_date = date("Y-m-d");
    $created_dateFull = date("Y-m-d H:i:s");
    $reportPin = $_POST['reportPin'];
    $reportWeekNo = $_POST['reportWeekNo'];
    $sendercellname = $_POST['sendercellname'];
    $sendername = $_POST['sendername'];

    if($row3['reportWeekDate'] != $week){ 
        // insert query and execute
        $successMSG = "YAY!";
    }else{
        $errMSG = "NAH !"; // echo you can only submit once a week
        }

}
?>

So the issue i face now is that any users that want to submit report keep getting warning "$errMSG = "NAH !"; // echo you can only submit once a week". Whereas it supposed to be for the user who had already submitted.

I really hope someone can help me out.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire