Reputation: 45
Someone please help me with the reason as to why this is not working. i am checking if a record exists with count. if it exits no add new, if it does not add new allowed.
<?php
// Setting a value for the new week to be added
$TeamOwner = $teams->MemberID->CurrentValue;
$OldWeek = $teams->WeekID->CurrentValue;
$NewWeek = ($OldWeek+1);
echo $NewWeek;
$con=mysqli_connect("localhost","root","","soccer_team");
// Check connection
if (mysqli_connect_errno())
{
throw new Exception(mysqli_connect_error(), mysqli_connect_errno());
getPosts($con); "Please try again later: " . mysqli_connect_error();
} else {
$result = mysqli_query($con,"SELECT COUNT(*) c FROM teams WHERE MemberID= $TeamOwner AND WeekID= $NewWeek");
$row = mysqli_fetch_array($result);
$row = $result->fetch_row();
$total = $row[0];
echo "No of Teams created this week: " . $total;
mysqli_close($con);
}
switch ($total)
{
case ($total== 0):
?><script> document.getElementById('btnAction').disabled = true; </script><?php
break;
case ($total == 1):
echo 'You cannot create another team, please update your existing team';
break;
}
?>
Upvotes: 0
Views: 62
Reputation: 7530
Maybe change the start to MemberID AND add "as c".
SELECT COUNT(MemberID) as c FROM teams WHERE MemberID= $TeamOwner AND WeekID= $NewWeek"
Upvotes: -1
Reputation: 2859
You are fetching from you result set twice:
$row = mysqli_fetch_array($result);
$row = $result->fetch_row();
You need to remove one of these.
Upvotes: 2