我想让管理员能够激活用户帐户,这样我就必须将状态设置为活动和非活动当我运行代码时,我得到4状态忙碌的不活跃的忙碌的不活跃的你会在这里找到一张截图来了解我面临的问题
https://i.stack.imgur.com/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
}
}
?>
您的代码可能格式不正确。试试这个:
<?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 } ?>