472,352 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 software developers and data experts.

Restrict Duplicate entries

18
hi all,
i had a users page in which the Admin can add users.so while adding a user i am able to restrict the duplicate entries(same names).Those users will be displayed in a table, and there is a edit button, so Admin can edit users account(like active,inactive etc). here is my problem when i click on edit button a pop up wil open and i didnt change any thing and click update button, as i didnt change anything it should update but i am getting a popup as user already exist. so can any one...
Thanks in advance..
here is my code
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <?php
  4. $id=$_GET['f1'];
  5. include 'connection.php';
  6.  
  7. $query="select * from users where userid='$id'";
  8. mysql_error();
  9. $result = mysql_query ($query) ;
  10. $num=mysql_num_rows($result);
  11. $i=0;
  12. While($i < $num)
  13. {
  14. $userid=mysql_result($result,$i,"userid");
  15. $sqlusername=mysql_result($result,$i,"username");
  16. $password=mysql_result($result,$i,'password');
  17. $role=mysql_result($result,$i,"role");
  18. $status=mysql_result($result,$i,'status');
  19. $allocatedmemory=mysql_result($result,$i,"allocatedmemory");
  20. $arr_id=split("[{ }-]" ,$allocatedmemory);
  21. $i++;
  22. }
  23. ?>
  24. <form action="update.php" method="post">
  25. <div>
  26. <center>
  27. <table>
  28.     <tr>
  29.         <td style="color: navy;">Userid</td>
  30.         <td><input type="text" readonly="readonly" name="userid" value="<? echo $userid; ?>"></td>
  31.     </tr>
  32.     <tr>
  33.         <td style="color: navy;">Username</td>
  34.         <td><input type="text" name="username" id="txtname" value="<? echo $sqlusername; ?>"></td>
  35.     </tr>
  36.     <tr>
  37.         <td style="color: navy;">Password</td>
  38.         <td><input type="password" name="password" id="pwd" value="<? echo $password; ?>"></td>
  39.     </tr>
  40.         <tr>
  41.         <td style="color: navy;">Status:</td>
  42.         <td><select name="status">
  43.         <?php
  44.         if($status == 1)
  45.         {
  46.             echo '<option value="Active" selected="selected">Active</option>';
  47.             echo '<option value="Inactive">Inactive</option>';
  48.         }
  49.         else
  50.         {
  51.             echo '<option value="Inactive" selected="selected">Inactive</option>';
  52.             echo '<option value="Active">Active</option>';
  53.         }
  54.         ?>
  55.         </select></td></tr>
  56.         <tr>
  57.         <td style="color: navy;">Allocatedmemory</td>
  58.         <td><input type="text" onkeypress="return isNumberKey(event)" id="am" name="allocatedmemory" value="<? echo $arr_id[0]; ?>"></td>
  59.         <td><select name="size">
  60.         <?php
  61.            if($arr_id[1]== "KB")
  62.            {
  63.                 echo '<option value="MB">MB</option>';
  64.                 echo '<option value="KB" selected="selected">KB</option>';
  65.            }
  66.            else
  67.            {
  68.                    echo '<option value="MB" selected="selected">MB</option>';
  69.                 echo '<option value="KB">KB</option>';
  70.  
  71.            }?>
  72.         </select>
  73.         </td>
  74.     </tr>
  75.         <tr>
  76.             <td></td>
  77.  
  78.         <td><input type="submit" name="btn" value="Update" onclick="return (confirm('Are you sure you want to Update this?'),check())"/>
  79.         <input type="submit" name="btn" value="Delete" onclick="return (confirm('Are you sure you want to delete this?'))"/></td>
  80.     </tr>
  81.     </table>    
  82. </center>
  83. </div>
  84. </form>
  85. </body>
  86. </html>
  87. <?php
  88.  $user=$sqlusername;
  89. echo $user;
  90.  if(isset($_POST['btn'])) 
  91. {
  92.     include 'connection.php';
  93.      if($_POST[btn]== 'Update')
  94.  {
  95.       $pname=$_POST['username']; 
  96.      if($_POST[status] == 'Active')
  97.         $_POST[status] = 1;
  98.     else{
  99.             $_POST[status] = 0;
  100.         }
  101.        echo $pname;
  102.        if($user==$pname)
  103.      {
  104.          mysql_query("UPDATE users SET username = '$_POST[username]',password = '$_POST[password]', role = '1', status = $_POST[status], allocatedmemory = '$_POST[allocatedmemory] $_POST[size]' WHERE userid = '$_POST[userid]'");
  105.          echo "<script language='javascript'>
  106.                 alert('User details updated');
  107.                 </script>";
  108.                 echo "<script language='javascript' type='text/javascript'>
  109.                 window.close();
  110.                 </script>";
  111.      }
  112.      else{
  113.             $query="select * from users where username='$pname'";
  114.             mysql_error();  
  115.             $result=mysql_query($query);
  116.             $count=mysql_num_rows($result);
  117.             if($count==0)
  118.             {
  119.                 mysql_query("UPDATE users SET username = '$_POST[username]',password = '$_POST[password]', role = '1', status = $_POST[status], allocatedmemory = '$_POST[allocatedmemory] $_POST[size]' WHERE userid = '$_POST[userid]'");
  120.             }
  121.             else
  122.             {
  123.                 echo "<script language='javascript'>
  124.                     alert('Username already exists');
  125.                     </script>";
  126.             }
  127.          }
  128.  }
  129.  else if($_POST[btn] == 'Delete')
  130.   {
  131.         mysql_query("Delete from users where userid ='$_POST[userid]'");
  132.         echo "<script language='javascript'>
  133.               alert('Data Deleted');
  134.               </script>";
  135.         echo "<script language='javascript' type='text/javascript'>
  136.                window.close();
  137.                </script>";        
  138.   }
  139.  ?>
May 22 '10 #1
0 1731

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an...
3
by: andreas.maurer1971 | last post by:
Hi all, since a few years I use the following statement to find duplicate entries in a table: SELECT t1.id, t2.id,... FROM table AS t1 INNER...
4
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it ...
5
by: Chris Lasher | last post by:
Hello Pythonistas! I'm looking for a way to duplicate entries in a symmetrical matrix that's composed of genetic distances. For example, suppose I...
1
by: calebm12 | last post by:
Quick Question. I gotta a database with fields firstname, lastname, and hobby, etc. I dont want to allow duplicate entries for the name. For...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ...
12
by: joestevens232 | last post by:
Hello Im having problems figuring out how to remove the duplicate entries in an array...Write a program that accepts a sequence of integers (some of...
7
by: php_mysql_beginer911 | last post by:
Hi .. i am trying to update a table where if field contents any duplictaed entries than one of the field should be updated with random number...
3
by: poolboi | last post by:
hey guys, i'm stuck with finding a sql statement for filtering out duplicate entry i got like thousands of entry but i would like to put a...
1
by: ahmedahmed | last post by:
how to restrict duplicate values in msflexgridcontrol
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.