473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1759

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 error - it dropped the duplicate entries and ran...
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 JOIN table AS t2 ON t1.field = t2.field WHERE...
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 - # Code for storing the values in the file...
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 have a matrix like the following: A B ...
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 instance....no john smith twice....but there can be a...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
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 which may repeat) as input into an array. Write...
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 which is unique so i can make all entries unique i...
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 filter on so i can see all the duplicate entries ...
1
by: ahmedahmed | last post by:
how to restrict duplicate values in msflexgridcontrol
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.