Jump to content
php.lv forumi

Nestrādā pašveidots PHP+MySql AdminCP


RaaapuLis
 Share

Recommended Posts

Lieta: Ir Neliels, parasts Admina Panelis, un īsāk sakot skripts izpildās tikai līdz vietai, kur rakstīts // Līdz šejienei <<, tālāk ejot, viņš (username = $_SESSION['user']) username nomaina uzreiz uz 0 un vnk atgriezas uz admin.php lapu..

 

Nespēju atrisināt problēmu, varbūt kāds var palīdzēt?

 

Skripts:

<?php
session_start();
include("include/db.php");
$admin = mysql_fetch_array(mysql_query("SELECT * FROM user WHERE username  = '".$_SESSION['user']."' "));

if($admin['level'] != '3'){
header('Location: index.php');
exit;
}


if($_GET['p'] == 'user'){

$user = mysql_query("SELECT * FROM user ORDER BY id");
while($row_user = mysql_fetch_array($user)){
echo ''.$row_user["username"].' - '.$row_user["password"].' - '.$row_user["email"].' - '.$row_user["level"].' | <a href="?p=user&labot='.$row_user["id"].'"><b>Labot</b></a><br>';
} 
echo "<hr>";

// Līdz šejienei <<

if($_GET['p'] == 'user' && $_GET['labot']){
$row_user_labot = mysql_fetch_array(mysql_query("SELECT * FROM user WHERE id='".$_GET['labot']."'"));
echo "
<form method='POST' action=''>
<input type='text' name='username' value='".$row_user_labot["username"]."'><br>
<input type='text' name='password' value='".$row_user_labot["password"]."'><br>
<input type='text' name='email' value='".$row_user_labot["email"]."'><br>
<select name='level'>
<option ";if($row_user_labot["level"] == '1'){ echo "SELECTED";} echo " value='1'>Lietotājs</option>
<option ";if($row_user_labot["level"] == '2'){ echo "SELECTED";} echo " value='2'>Moderators</option>
<option ";if($row_user_labot["level"] == '3'){ echo "SELECTED";} echo " value='3'>Admins</option>
</select></br>
<input type='submit' name='user_labot' value='Labot'>
</form><hr>
";

if(isset($_POST['user_labot'])){

mysql_query("UPDATE user SET username='".$_POST['username']."', password='".$_POST['password']."', email='".$_POST['email']."', level='".$_POST['level']."' WHERE id='".$_GET['labot']."'");
header("location:admin.php");
}
}

}
?>

Edited by RaaapuLis
Link to comment
Share on other sites

Nu vispār jau nē ;)

<a href="?p=user&labot='.$row_user["id"].'"><b>Labot</b></a>

No tāvar secināt ka saite izstās šādi: ?p=user&labot=1

 

Bet nu vispār pat ja būtu tā, kātu teiktu, tas neko nedotu, jo skripts netiek līdz tai vietai..

 

Vnk parāda visu lietotāj usarakstu un kad uzspiež uz Labot, tad arī sākās problēmas.. => Nika vietā - 0, un līdz ar to nekas tālāk no lietotāja opcijām neiet..

Link to comment
Share on other sites

Un kam, tavuprāt, būtu jābūt tajos print_r GET un POST?

 

p.s. TUKŠUMS taču tur ir, uzspiežot uz labot lietotājus -> ?p=user

tālāk spiežot uz noteikta lietotāja - Labot, Nika vietā 0, un kr4 viss pazuud, atpakalj uz admin.php sākumu

 

EDIT tomēŗ kļūdijos es, skripts nojūdzas, uzreiz kā uzspiež uz labot lietotājus

 

taču citas sadaļas iet un ir veidotas pilniigi peec taada paša principa

Edited by RaaapuLis
Link to comment
Share on other sites

Pamēģini, ko šādu

 

<?php
session_start();
include("include/db.php");
$admin = mysql_fetch_array(mysql_query("SELECT * FROM user WHERE username  = '".$_SESSION['user']."' "));

if($admin['level'] != '3'){

 header('Location: index.php');
 exit;

}else{


 if($_GET['p'] == 'user'){

   $user = mysql_query("SELECT * FROM user ORDER BY id");
   while($row_user = mysql_fetch_array($user)){
   echo ''.$row_user["username"].' - '.$row_user["password"].' - '.$row_user["email"].' - '.$row_user["level"].' | <a href="?p=user&labot='.$row_user["id"].'"><b>Labot</b></a><br>';
   } 
   echo "<hr>";

   // Līdz šejienei <<

   if($_GET['p'] == 'user' && $_GET['labot']){

     $row_user_labot = mysql_fetch_array(mysql_query("SELECT * FROM user WHERE id='".$_GET['labot']."'"));
     echo "
     <form method='POST' action=''>
     <input type='text' name='username' value='".$row_user_labot["username"]."'><br>
     <input type='text' name='password' value='".$row_user_labot["password"]."'><br>
     <input type='text' name='email' value='".$row_user_labot["email"]."'><br>
     <select name='level'>
     <option ";if($row_user_labot["level"] == '1'){ echo "SELECTED";} echo " value='1'>Lietotājs</option>
     <option ";if($row_user_labot["level"] == '2'){ echo "SELECTED";} echo " value='2'>Moderators</option>
     <option ";if($row_user_labot["level"] == '3'){ echo "SELECTED";} echo " value='3'>Admins</option>
     </select></br>
     <input type='submit' name='user_labot' value='Labot'>
     </form><hr>
     ";

     if(isset($_POST['user_labot'])){

       mysql_query("UPDATE user SET username='".$_POST['username']."', password='".$_POST['password']."', email='".$_POST['email']."', level='".$_POST['level']."' WHERE id='".$_GET['labot']."'");
       header("location:admin.php");

     }

   }

 }

}
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...