0

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;
 }
 ?>
2
  • 1
    are you getting any error? Commented Mar 24, 2014 at 6:45
  • 2
    Why using both OO & Procedural style mysqli_fetch_array & fetch_row ?
    – Rikesh
    Commented Mar 24, 2014 at 6:46

2 Answers 2

2

You are fetching from you result set twice:

$row = mysqli_fetch_array($result);
$row = $result->fetch_row();

You need to remove one of these.

-1

Maybe change the start to MemberID AND add "as c".

SELECT COUNT(MemberID) as c FROM teams WHERE MemberID= $TeamOwner AND WeekID= $NewWeek"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.