0

below is my code to use chekc boxes to update my status field to either a 1 or 2, but altohught it doesnt show any errors, it wont update HELP PLZ

</style>
</head>

<body>
<table width="744" height="536" border="1">
  <tr>
    <td height="63" colspan="4" bgcolor="#8BCB6A"><p><img src="CO-OP title.gif" width="407" height="64" />
      <?php

$connection=mysql_connect('localhost','but09081489','');
$database = mysql_select_db('but09081489',$connection);

$EmployeeID=$_POST['EmployeeID'];
$Password=$_POST ['Password'];
$NewEmployeeID=$_POST ['NewEmployeeID'];

if(isset($_POST['block1']) == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE NewEmployeeID LIKE '$NewEmployeeID' AND BlockID = '1'");
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE NewEmployeeID LIKE '$NewEmployeeID' AND BlockID = '1'");  
    }   


if(isset($_POST['block2']) && 
    $_POST['block2'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '2'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '2'");  
    }   

if(isset($_POST['block3']) && 
    $_POST['block3'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '3'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '3'");  
    }   


if(isset($_POST['block4']) && 
    $_POST['block4'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '4'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '4'");  
    }   


if(isset($_POST['block5']) && 
    $_POST['block5'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '5'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '5'");  
    }   


if(isset($_POST['block6']) && 
    $_POST['block6'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '6'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '6'");  
    }   


if(isset($_POST['block7']) && 
    $_POST['block7'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '7'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '7'");  
    }   


if(isset($_POST['block8']) && 
    $_POST['block8'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '8'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '8'");  
    }   


if(isset($_POST['block9']) && 
    $_POST['block9'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '9'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '9'");  
    }   


if(isset($_POST['block10']) && 
    $_POST['block10'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '10'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '10'");  
    }   


if(isset($_POST['block11']) && 
    $_POST['block11'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '11'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '11'");  
    }   


if(isset($_POST['block12']) && 
    $_POST['block12'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '12'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '12'");  
    }   


if(isset($_POST['block13']) && 
    $_POST['block13'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '13'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '13'");  
    }   


if(isset($_POST['block14']) && 
    $_POST['block14'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '14'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '14'");  
    }   


if(isset($_POST['block15']) && 
    $_POST['block15'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '15'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '15'");  
    }   


if(isset($_POST['block16']) && 
    $_POST['block16'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '16'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '16'");  
    }   


if(isset($_POST['block17']) && 
    $_POST['block17'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '17'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '17'");  
    }   


if(isset($_POST['block18']) && 
    $_POST['block18'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '18'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '18'");  
    }   


if(isset($_POST['block19']) && 
    $_POST['block19'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '19'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '19'"); 
    }   


if(isset($_POST['block20']) && 
    $_POST['block20'] == '1') 
    {
    $Status="1";
     mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID'AND BlockID = '20'");  
    }
    else
    {
       $Status="2";
        mysql_query("UPDATE avalibility SET Status='$Status' WHERE EmployeeID LIKE '$NewEmployeeID' AND BlockID = '20'");  
    }   



    $sqlName="SELECT * FROM employeedetails WHERE EmployeeID LIKE '$NewEmployeeID'"; 
$queryName = mysql_query($sqlName,$connection);
$recordName = mysql_fetch_assoc($queryName);
$Name=$recordName['Name'];
echo $Name;
    ?>
     </p></td>
  </tr>
  <tr>
    <td width="227" height="41" bgcolor="#8BCB6A" class="CENTER">Manager View</td>
    <td width="501" colspan="3" rowspan="8" bgcolor="#003366"><div align="center">
      <table width="454" height="353" border="1">
        <tr>

          <td height="347" bgcolor="#E0EEFE"><p align="right">New Employee Added</p>
            <p align="right">&nbsp;</p></td>

        </tr>
      </table>
    </div></td>
  </tr>
  <tr>
  <td height="27" bgcolor="#8BCB6A"><?php 
    echo "<a href='Rota page.php?EmployeeID=$EmployeeID&Password=$Password'>View Rota</a>";
    ?>
    </td>
  </tr>

  <tr bgcolor="#FF9900">

    <td height="61" bgcolor="#8BCB6A"><?php 
    echo "<a href='AddNewEmployee.php?EmployeeID=$EmployeeID&Password=$Password'>Edit News Feed </a>";
    ?></td>
  </tr>
  <tr bgcolor="#FF9900">
    <td height="28" bgcolor="#8BCB6A"><span class="CENTER1">

    <a href="EditNewsFeed.php"></a><?php 
    echo "<a href='EditNewsFeed.php?EmployeeID=$EmployeeID&Password=$Password'>Edit News Feed </a>";
    ?></span></td>


  </tr>
  <tr bgcolor="#FF9900">
  <td height="28" bgcolor="#8BCB6A"><?php 
    echo "<a href='AddNewEmployee.php?EmployeeID=$EmployeeID&Password=$Password'>Add New Employee</a>";
    ?>
   </td>
  </tr>
  <tr bgcolor="#FF9900">
  <?php 
    echo "<a href='loginfull.php?EmployeeID=$EmployeeID&Password=$Password'>Home</a>";
    ?>
    <td height="123" bgcolor="#8BCB6A"> <?php 
    echo "<a href='loginfull.php?EmployeeID=$EmployeeID&Password=$Password'>Home</a>";
    ?></td>
  </tr>
</table>
</body>
</html>

Edited by diafol: fixed formatting

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Tempest will
0

THis is extremely wasteful. How about:

for($x=1;$x<21;$x++){
  $status = (isset($_POST['block' . $x]) && $_POST['block' . $x] == '1')? 1 : 2;
  mysql_query("UPDATE avalibility SET Status= $status WHERE EmployeeID = $NewEmployeeID AND BlockID = $x");  
}

I haven't checked the mysql, but why are you using LIKE instead of = ?
You should also use mysql_real_escape_string to clean all variables from a form before inserting into a DB, otherwise you're open to all sorts of nasties.

$sqlName="SELECT * FROM employeedetails WHERE EmployeeID LIKE '$NewEmployeeID'";

Again, why LIKE?

Edited by diafol: n/a

0

the error was it was trying to connect to my college data base and not my home one !

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.