-2

I want to give the admin the ability to activate the user account so I have to status active and inactive When I run my code I get 4 status Active Inactive Active Inactive You will find here a screenshot to understand the problem I’m facing

https://i.sstatic.net/UBNOQ.png

 if(isset($_GET['id_user'])){ include("conexion.php"); $rep=$db->query("select * from user WHERE id_user=" .$_GET['id_user'] ); while($l=$rep->fetch()){ echo " <form class= mainSettingsForm add method='POST'> <label>Numero utlisateur :</label> <input disabled='disabled' type='text' name='ref' value=' ".$l[0]." ' ></input> <input name='id_user2' type='hidden' value='".$l[0]."' ></input> <label>Nom utlisateur : </label> <input type='text' name='username2' value='".$l[1]."' > <label> nom : </label> <input type='text' name='nom2' value='".$l[3]."' > <label> prenom : </label> <input type='text' name='prenom2' value='".$l[4]."' > <label> Statut : </label> <select name=statut > if ($l[6] ==active) { echo ' <option value=active >active</option> <option value=inactive >inactive</option> }' else { echo ' <option value=inactive >inactive</option> <option value=active >active</option> }' </select> <input class=btn-primary type='submit' name='enregistrer' value='enregistrer' > </form>"; // fin echo } } ?> 
2

1 Answer 1

0

Your code may not have been properly formed. Try this instead:

 <?php if( isset($_GET['id_user']) ){ include("conexion.php"); $rep = $db->query( "select * from user WHERE id_user=" . $_GET['id_user'] ); // YOU ARE FETCHING A SINGLE USER... NO NEED FOR A LOOP... // JUST GET THE ARRAY OBJECT AND USE IT DIRECTLY... $l = $rep->fetch(); ?> <form class= mainSettingsForm add method='POST'> <label>Numero utlisateur :</label> <input disabled='disabled' type='text' name='ref' value='<?php echo $l[0]; ?>'/> <input name='id_user2' type='hidden' value='<?php echo $l[0]; ?>'/> <label>Nom utlisateur :</label> <input type='text' name='username2' value='<?php echo $l[1]; ?>' /> <label>Nom :</label> <input type='text' name='nom2' value='<?php echo $l[3]; ?>' /> <label>Prenom :</label> <input type='text' name='prenom2' value='<?php echo $l[4]; ?>' /> <label>Statut :</label> <select name=statut > <option value='active' <?php if($l[6] == "active"){ echo "selected";} ?> >active</option> <option value='inactive' <?php if($l[6] == "inactive"){ echo "selected";} ?>inactive</option> </select> <input class=btn-primary type='submit' name='enregistrer' value='enregistrer' > </form> <?php } ?> 
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer, but I’m still getting active as a first choice even if the status of the user is inactive! Regards.
@AbdelhakOhammou What is the content of $l[6]? Can you do a var_dump($l[6])? This will tell you if $l[6] contains the String "active" or "inactive". Let me know what you find then. Cheers...
I fixed the problem, thank you for your time, I really appreciate.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.