Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3611206
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:50:53+00:00 2026-05-18T21:50:53+00:00

How are you all, hope every one here is OK, now I have a

  • 0

How are you all,

hope every one here is OK,

now I have a form that the admin can create users and he can delete users as will let me display the code first

this is my code

> > <?php error_reporting(E_ALL);
> 
> session_start();
>   if(!isset($_SESSION['login']) ||
> $_SESSION['login']!='1' )         {
>       header("Location:loginpage.php");
>       } ?>
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD
> XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html
> xmlns="http://www.w3.org/1999/xhtml">
> <head> <meta http-equiv="Content-Type"
> content="text/html; charset=utf-8" />
> <title>My Control panel</title> <link
> href="../css_style.css"
> rel="stylesheet" type="text/css" />
> </head>
> 
> 
> 
> <body> <div id="werpper"> <div
> id="content">
> 
> <div id="header">My control -
> Panel</div> <div id="body_cntent">  
> <div id="left_side">   <p>Home and
> instructions</p>   <p><a
> href="../control_panel.php">main
> directory</a></p>   <p><a
> href="add_event.php">Add new
> event</a></p>   <p><a
> href="../editoccasion.php">Control
> Occasion's</a></p>   <p><a
> href="add_photos_and_occasion.php">Add
> Photos_occasion</a></p>   <p><a
> href="../signout.php">Sign out</a></p>
> </div> <div id="right_side">
> 
> <h2>Add new user</h2>
> 
> <form action="" method="post">
> 
> <table width="600" border="0"
> cellpadding="5" cellspacing="0">  
> <tr>
>     <td width="78">User name</td>
>     <td width="2">&nbsp;</td>
>     <td width="149"><input type="text" name="uname" value="" /></td>
>     <td width="332" rowspan="5" align="left" valign="top"><p
> class="red">For Administration use
> only.</p>
>       <p>You can add or delete users from <a
> href="edit_users.php">here</a><br />
>         You can't edit any user if you like to change any user account you
> can delete the user and create it
> again with the new
> information.</p></td>   </tr>   <tr>
>     <td>Password</td>
>     <td>&nbsp;</td>
>     <td><input type="text" name="pass" value="" /></td>
>     </tr>   <tr>
>     <td>&nbsp;</td>
>     <td>&nbsp;</td>
>     <td><input type="submit" name="submit" value="Add user" /></td>
>     </tr>   <tr>
>     <td>&nbsp;</td>
>     <td>&nbsp;</td>
>     <td>&nbsp;</td>
>     </tr>   <tr>
>     <td>&nbsp;</td>
>     <td>&nbsp;</td>
>     <td align="right">&nbsp;</td>
>     </tr> </table> </form>
> 
> </div> </div>
> 
> <div id="footer"></div> </div> </div>
> 
> <?php
>       if (isset($_POST['submit'])) {
>               include_once "../config/config.php";
>               $uname = $_POST['uname'];       $pass =$_POST['pass'];
>               $check = "select * from users where id = {$uname}";         $result_check
> = $db->query($check)or die($db->error);
>       
>               while ($row = $result_check -> fetch_object()) {
>                       if(num_rows == 1){
>               
>               echo "error";
>               
>               }else{
>               $add_user = "insert into users (id, uname, pass) values ('',
> '$uname', '$pass')";
>               $result = $db -> query($add_user) or die ("$db->error");
>               if ($result) {
>                       echo "user added successfuly";
>                       }else{
>               
>               echo "There was an error please try again later";
>               
>               }           }       }   } ?>
> 
> </body> </html>

all I need here to know is how to solve the problem of this code

$check = "select * from users where id = {$uname}";
        $result_check = $db->query($check)or die($db->error);


        while ($row = $result_check -> fetch_object()) {

            if(num_rows == 1){

                echo "error";

                }

how can I avoid duplication users in my db

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:50:54+00:00Added an answer on May 18, 2026 at 9:50 pm

    I’m not sure which database library you’re using and what all its methods are, so I made this with plain mySQL for if you went the route of making the uname (username) field a UNIQUE INDEX —

    // instantiate database connection
    $db = mysql_connect( .. );
    
    // assuming the id field is auto incrementing, it can be left out of the query
    $add_user  = "INSERT INTO users (uname, pass) ";
    $add_user .= "VALUES ('" . mysql_real_escape_string($uname) . "', ";
    $add_user .= "'" . mysql_real_escape_string($pass) . "')";
    
    if (mysql_query($add_user, $db))
    { 
        if (mysql_affected_rows($db) == 1)
        {
            // New user added, do something
        }
    } 
    else
    { 
        if (mysql_errno($db) == 1062) 
        { 
            // Duplicate username, do something 
        } 
        else
        { 
            // A different database error occurred
            die('Error: ' . mysql_error());
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my application workflow. I have a ref cursor that is populated with all
hope every one is doing well :) I have struck with retrieving the month
I have a fruits form that has one FieldList object for the bananas: bananas
Hope you're having a good Friday and stuff... okay, so here's my question: All
Using ASP.net and c# using visual studio 2010 Hi all, I hope some one
I hope you all have a nice day. I want to write a web
I have a couple of Activities which all contain one CustomView , a titlebar.
I have read several interesting C#/F# comparisons here on stackoverflow. So, first of all,
First time I ask something here, I hope you people will be as helpful
it's my first question here and I hope that I'm doing it right. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.