0

want to hide insert and edit form while show all date
and if we do edit/insert hide date which are showing this is my code i am the beginer so i want your help

<?php
include 'header.php';//caling header
if(empty($_SESSION['UserName'])){
header("Location: login.php");
exit;}
$start=0;
$limit=10;
$page='';
$tbl_name="users";      
$targetpage = "users.php";  //your file name  (the name of this file)
if(isset($_POST['fullname'])){
$term=$_POST['fullname'];}
if(isset($_GET['page'])){
$page=$_GET['page'];
$start=($page-1)*$limit;
}
{

if(isset($_POST['Submit'])){
$query=mysql_query
("select * from users  where FirstName like '%$_REQUEST[fullname]%' LIMIT $start, $limit");
$search_num_rows = mysql_num_rows($query);
echo "<div class='main'>";
echo"Found " .$search_num_rows. " results for " .$term. "</div>";
}
else{
$query=mysql_query("select * from users LIMIT $start, $limit");
}

echo "<div class='main'>";
echo "<table border='1'>
<tr class='tableheader'>
<th><a href=' users.php'>
<img src='images/create.png' name='link'>Add New </a></th>
<th>First Name</th>
<th>Last name</th>
<th>User Id</th>
<th>User Name</th>
<th>Password</th>
<th>Email</th>
<th>Created Date</th>
<th>Gender</th>
<th>Delete</th>
</tr>";
while($row=mysql_fetch_array($query)){
echo "<tr class='tablerow'>";
$query_sting = "Id={$row['UserID']}";
$url1="$targetpage?".$query_sting;
echo "<td><a href='$url1'><img src='images/UPDATE.png'>Edit</a></td>";

echo "<td>" . $row['FirstName']      ."</td>";
echo "<td>" . $row['LastName']       ."</td>";
echo "<td>" . $row['UserID']     ."</td>";
echo "<td>" . $row['UserName']       ."</td>";
echo "<td>" . $row['Password']       ."</td>";
echo "<td>" . $row['Email']          ."</td>";
echo "<td>" . $row['CreatedDate']    ."</td>";
echo "<td>" . $row['Gender']     ."</td>";
$query_sting = "Id={$row['UserID']}";
$url = " user_delete.php?". $query_sting;
echo "<td><a href='$url' onclick='return checkDelete()'><img src='images/DELETE.png'  ></a></td>";
echo "</tr>";
}
echo "</table>";
$rows=mysql_num_rows(mysql_query("select * from users"));
$total=ceil($rows/$limit);
echo "<ul class='page'>";
for($i=1;$i<=$total;$i++){
if($i==$page) {
echo "<li class='current'>".$i."</li>"; }
else {
echo "<li><a href='?page=".$i."'>".$i."</a></li>"; }
}
echo "</ul>";
if(isset($_POST['insert'])){
$Number     =$_POST['pagination'];
$Number=urlencode($Number);
header ("Location: users.php?page=$Number"); 
if ($Number >= $i || '0'){
header ("Location: users.php?page=1"); 
exit;
}}}
?>

 <form method="post" id="frm" name="frm" action='users.php'>
    <table width="500" border="0">
    <tr>
      <th>Search :</th>
      <td><input type="text"  name="fullname" id="fullname" /></td>
    </tr>
    <tr>
      <td><input type="submit" name="Submit" value="Search" /></td>
      <td>&nbsp;</td>
    </tr>
  </form>
  <form style="width:50%"  method="post" id="123" name="1234" action="" >
    <tr>
      <th>Go To Page:</th>
      <td><input type="text" value=""  name="pagination" class=""/></td>
    </tr>
    <tr>
      <td><input name="insert" type="submit" class="button" value="go"/></td>
      </table>
  </form>

<?php

$First_name=
$Last_name=
$User_Id=
$User_Name=
$Password=
$Email=
$Created_Date=
$Gender="";
if(isset($_GET['Id'])){//checking if Id is getting or not
$Id=$_GET['Id'];//geting Id
$query = mysql_query("SELECT  
* 
FROM
users 
WHERE UserId = '$Id'");//select query for fetching data from tabel users for display data in update
$row = mysql_fetch_array($query);//fetching query data in array
$First_name=$row['FirstName'];
$Last_name=$row['LastName'];
$User_Name=$row['UserName'];
$Password=$row['Password'];
$Email=$row['Email'];
$Created_Date=$row['CreatedDAte'];
$Gender=$row['Gender'];
}
else{
    echo"problem1";
}
$newq=mysql_query("SELECT * from userrights WHERE UserId=$Id");
$arr=array();

while($r1=mysql_fetch_array($newq)){
$menuid=$r1['MenuId'];
$arr[]=$menuid;
}
if(isset($_POST['insert'])){//button per click hoa toh post kerdu
$FirstName      =$_POST['firstName'];
$LastName       =$_POST['lastName'];    
$UserName       =$_POST['userName'];
$gender1        =$_POST['gender'];  
$pass           =$_POST['password'];
$mail           =$_POST['email'];
$page           =$_POST['page'];
$sql_pass   =NULL;//using for password

if(!empty($pass)){ //agar pass empty to kuch nahi  hn
$sql_pass =" , Password = '$pass' ";// agar emty na hn toh password post kerdau 
}
if (isset($Id)){//agar Id get ker raha hn toh update hn
$query33 = mysql_query("Delete  FROM userrights WHERE UserId='$Id'");
$sql="UPDATE 
users 
SET
FirstName = '$FirstName',
LastName = '$LastName',
UserName = '$UserName',
Gender = '$gender1' $sql_pass,
Email = '$mail' 
WHERE `UserID` ='$Id'";//updating 

foreach($page as $page_name){
$sql22.= "('$Id','$page_name'),";
}//updating

$sql22 ="INSERT INTO userrights ( UserId , MenuId ) VALUES". trim($sql22,',');

if (!mysql_query($sql)){//agar query nahi chalay
die('Error: '. mysql_error());//toh error ajie
}
mysql_query($sql22);
//dusri query chalanay ka liya
echo "Sucessfully Updated";
header("Location:  users.php"); 
exit;
}
else{//agar Id get nahi keray toh
$query = mysql_query("SELECT 
UserName 
FROM
users 
WHERE UserName = '$UserName'");
if (mysql_num_rows($query) != 0){
die( "User Name already exists");//username check kerna ka liya phelay say mojood hn ya nahi
}
$sql1=mysql_query("INSERT INTO users (
FirstName,
LastName,
UserName,
Gender,
PASSWORD,
Email
) 
VALUES
(
'$FirstName',
'$LastName',
'$UserName',
'$gender1',
'$pass',
'$mail'
)");//inserting in tbl
$last_id = mysql_insert_id();//geting auto increment ID

foreach($page as $page_name){
$sql2.= "('$last_id','$page_name'),";
}
$sql2 ="INSERT INTO userrights ( UserId , MenuId ) VALUES". trim($sql2,',');
if (!($sql1)){//agar data inset na hn toh
die('Error: ' . mysql_error());//error show kerdain
}
else{mysql_query($sql2);}//agar uper wali quety chat chie hn to ya bhi chal jie ghie
echo "Sucessfully Registers";
mysql_close();
header("Location: users.php");
exit;
}
}
?>
<form style="width:100%"  method="post" id="form" name="admin" >
  <table class="viewjob" align="center" >
    <tr class="tableheader">
      <td align="center" colspan="4"> INsert </td>
    </tr>
    <tr class="tablerow">
      <td>First Name</td>
      <td><input type="text" value="<?php echo $First_name;?>"  
name="firstName" class="inputbox validate[required]"/></td>
      <td>Last Name</td>
      <td><input type="text" value="<?php echo $Last_name;?>"  name="lastName" 
class="inputbox validate[required]"/></td>
    </tr>
    <tr class="tablerow">
      <td>User Name</td>
      <td><input type="text" value="<?php echo $User_Name;?>"  name="userName" 
class="inputbox validate[required]"/></td>
      <td>Gender</td>
      <td><select class="select" name="gender"  >
          <option disabled="disabled" value="">Choose one</option>
          <option  value="male" <?php if($Gender == 'male'){ echo 'selected="selected"';}?>> Male </option>
          <option  value="female"  <?php if($Gender == 'female'){ echo 'selected="selected"';}?>> Female </option>
        </select></td>
    </tr>
    <tr class="tablerow">
      <td>Password</td>
      <td><input type="password" value=""  name="password" id="password"  
<?php

if(!isset($_GET['Id'])){echo "class='inputbox validate[required,minSize[4]]'";} ?>class=""/></td>
      <td>Confirm Password</td>
      <td><input type="Password"  name="cpassword" class="validate[equals[password]] text-input"/></td>
    </tr>
    <tr class="tablerow">
      <td>Email</td>
      <td><input type="text" value="<?php echo $Email;?>" 
name="email" class="inputbox validate[required,custom[email]"/></td>
      <td>User Access</td>
      <td><select   name="page[]" multiple="multiple"   size="5" >
          <option disabled="disabled" value="">Choose Any/More</option>
          <?php 
$query1=mysql_query("SELECT * FROM adminmenu");
while($row1=mysql_fetch_array($query1)){
$selected=NULL;
if(in_array($row1['MenuId'],$arr)){
$selected = 'selected="selected"';}
echo"<option value='$row1[MenuId]' $selected >".$row1['MenuName']."</option>";
}
?>
        </select></td>
    </tr>
    <tr class="tableheader">
      <td colspan="4" class="last"><input name="insert" type="submit" class="button"
<?php if(!isset($_GET['Id'])){echo "value='SignUp'";} else{echo "value='update'";} ?> />
        <input name="retype" type="reset" class="button" value="Reset"></td>
    </tr>
  </table>
</form>
<?php
include 'Footer.php';
?>
2
Contributors
1
Reply
24
Views
3 Years
Discussion Span
Last Post by iamthwee
0

There's too much code and it is untestable as we don't have your db. Sounds to me like a javascript issue anyway - as in you want to hide bits of the html.

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.