Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by maverick340 · Nov 24, 2011 at 09:38 PM · wwwloginmysqlphp

How Do i check for Duplicate username in database

Hi I am trying to implement a simple login system. I am using the WWW method and WWW.Form.

 //Create a form
 var form = new WWWForm();
 form.AddField("uname",userNameEntered);
 form.AddField("pass",passwordEntered);

 //Put all form data in a variable
 var rawData = form.data;
 var url = "http://url/login.php";

 var w = WWW(url,rawData);
 yield w;
 if(!w.error)
 {
   print("There was an error logging in: " + w.error);
 }

The problem is when i type in a duplicate username, mysql throws up an error as it should

 Error :Duplicate entry 'UnityUser' for key 'PRIMARY'

But the w.error() does not resolve as true ( I am guessing since there is no HTML or PHP error but rahter a MySQL error)

y question is how do i stop the users from using duplicate usernames ?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by jahroy · Nov 24, 2011 at 10:46 PM

You can make your php code return a certain value if there is a mysql error.

You can do this by using the php function named echo.

For example, you could return/echo 1 if a mysql error occurs.

(You might return/echo zero to represent success)

You can then check the return code in Unity by inspecting w.text, which will represent the content of the requested web page.

When you call echo in your php script, you're writing content to a web page.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Rabbit-Stew-dio · May 11, 2012 at 10:52 AM

Each HTTP request returns a status code. If everything goes well, your HTTP server returns the code "200 - OK".

Your PHP script returns 200 by default, unless you explicitly tell it otherwise. Make sure you set the correct response header. For server side errors, a code in the 5xx range is common, for user errors, a 4xx code is used.

I would return 400 (User error) to indicate that the parameters passed to the server were invalid.

Read the PHP manual on setting server-side response codes.

The status codes can be found in the HTTP-standard, or more conveniently here.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by dineshrajpurohit · Jun 20, 2012 at 03:24 AM

MySql will throw an error only when you try to store value in the database. If the username name is unique in database, sql will throw an error. In your code it seems like you are trying to log in and not tryin to register. In case of login you should not get a duplicate entry error. There has to be something wrong on your PHP code. Check if you are doing an INSERT query or SELECT query on the PHP side.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by shaystibelman · Nov 12, 2012 at 05:25 PM

This is my PHP file for double user verification:

 $insertedUsername=$_REQUEST['Username'];
     $insertedEmail=$_REQUEST['Email'];
     
     $sqlCheckUsername="SELECT 1 FROM Users WHERE Username = '" . mysql_real_escape_string($insertedUsername) . "'";
     $sqlCheckEmail="SELECT 1 FROM Users WHERE Email = '" . mysql_real_escape_string($insertedEmail) . "'";
     
     $queryUsername=mysql_query($sqlCheckUsername,$con) or die('error');
     $queryEmail=mysql_query($sqlCheckEmail,$con) or die('error');
     
     $Username = mysql_fetch_assoc($queryUsername);
       if(mysql_num_rows($queryUsername)!=0){
         echo "Username already exists, choose a different one";
     }elseif(mysql_num_rows($queryEmail)!=0){
         echo "E-Mail already registered";
     }else{
         echo "true";
     }

It basically checks to see if there already is a row with that username or email in it. I'm using OR, or rather, both controls, so people will know what they should change. Just like when your username OR password are wrong, that way you don't have any doubts for where you're wrong.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why do I get a newline (\n br) while sending a simple string from php to Unity c# 1 Answer

Login authentication on Unity 5 with php using xampp, and mysqli 0 Answers

C # Does not recognize characters after space 2 Answers

Problem using WWW with PHP and MYSQL 3 Answers

Retrieving data from a WWW php call? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges