-2
<?php 
include('conn.php');
if(isset($_GET['Valider'])) {
  $req="select acc from demch ";
  $rs=mysql_query($req) or die(mysql_error());
if (mysql_fetch_row($rs)) {
//while($row = mysql_fetch_row($rs)){ 
$acc=$row['acc'];
    if($acc=1){
$req1= "UPDATE etudiant, demch
   SET etudiant.groupe=demch.grpdes WHERE etudiant.dem_id=demch.dem_id ";
   $rs1=mysql_query($req1) or die (mysql_error());
   }
   elseif($acc=0){
    $req2="UPDATE etudiant SET message='votre demande est refuser' WHERE etudiant.dem_id=demch.dem_id ";
    $rs2=mysql_query($req2) or die (mysql_error());
   }
  }}//}
      ?>

it changes the group in both cases though I need it to be changed only if it 1

Cœur
  • 37,241
  • 25
  • 195
  • 267
avery
  • 3
  • 4
  • 1
    FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde Mar 29 '18 at 15:34
  • Uh oh `if($acc=1)` will always evaluate to true. – Aniket Sahrawat Mar 29 '18 at 15:36

1 Answers1

0
if($acc=1){

Should be

if($acc==1){

Or also

if($acc===1){

Cause right now you're not checking anything in your condition, you are just setting $acc value to 1.

Gregoire Ducharme
  • 1,095
  • 12
  • 24