Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Prezzy876 · Jul 31, 2018 at 01:40 AM · loginmysqlphpwwwformregistration

Mysql PDO Register user insert not inserting, no error feedback

Hello, I have my connection to database working, as i can check if a username already exists in my database, i also have populated a drop down list with options from my database, my issue is with registering a new user i.e. inserting the $_POST data into my table.

PHP is not sending an error i can research, i have tried the binding values method of PDO with no luck.Also strangely earlier i got a my php file to echo 0 at the files end an execute my debug.log for user added in my c# as www.text = 0 (see code), but no user was actually added to my database. Now i am stuck with no user insert, no error data from the php file to www.text, I have tried all day. Any help would be appreciated.

Here is the relevant code:

MYSQL TABLE:

 CREATE TABLE `players` (
   `id` int(10) NOT NULL,
   `country_id` smallint(11) UNSIGNED NOT NULL,
   `language_id` smallint(11) UNSIGNED NOT NULL,
   `first_name` varchar(50) CHARACTER SET utf8 NOT NULL,
   `last_name` varchar(50) CHARACTER SET utf8 NOT NULL,
   `email` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
   `username` varchar(16) COLLATE utf8_unicode_ci NOT NULL,
   `hash` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
   `salt` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
   `password_hint` text CHARACTER SET utf8 NOT NULL,
   `score` int(10) NOT NULL DEFAULT '0'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

 ALTER TABLE `players`
   ADD PRIMARY KEY (`id`),
   ADD UNIQUE KEY `username` (`username`),
   ADD KEY `country_id` (`country_id`),
   ADD KEY `language_id` (`language_id`);


CONNECT.PHP:

 <?php
 $host ='localhost';
 $user ='XYZ';
 $dbpassword = 'XYZ';
 $dbname = 'XYZ';
 
 //Set DSN
 
 $dsn = 'mysql:host='. $host.';dbname='. $dbname;
 
 //create PDO instance
 
 $pdo = new PDO($dsn, $user, $dbpassword);
 $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
 $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

  // THIS ERROR MODE IS ON
 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  ?>

PHP CODE: register.php

  <?php
         
         require 'connect.php'; //WORKING
         
         $first_name = $_POST["first_name"];
         $last_name = $_POST["last_name"];
         $username = $_POST["username"];
         $password = $_POST["password"];
         $password_hint = $_POST["password_hint"];
         //input from dropdowns
         $country_id = $_POST['country'];
         $language_id = $_POST['language'];
         
         $namecheckquerry = 'SELECT username FROM players WHERE username = ?';
         $stmt = $pdo->prepare($namecheckquerry);
         $stmt->execute([$username]);
         $nameCount = $stmt->rowCount();
         
         if($nameCount > 0){
           echo "3. A player with that Username already exists";
           exit();
         }
         
         //add user to table
         
         $salt = "\$5\$rounds=5000\$". "andrewjackson" . $username ."\$";
         $hash  = crypt($password, $salt);
         
         $insertuserqry = 'INSERT INTO players(first_name, last_name, username, hash, salt) 
                                        VALUES (:first_name, :last_name, :username, :hash, :salt)';
         $stmt = $pdo->prepare($insertuserqry);

          // ERROR STATEMENT NOT SENDING TO WWW.TEXT
          if (!$stmt) {
              echo "\nPDO::errorInfo():\n";
              print_r($dbh->errorInfo());
           }

         $stmt->execute(['first_name'=> $first_name , 'last_name'=> $last_name , 'username'=> 
         $username, 'hash'=> $hash, 'salt'=> $salt]);
         
         echo '0';
         
         ?>

C# CODE:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class registerme_new : MonoBehaviour
 {
  
 
 
     public InputField firstnamefield;
     public InputField lastnamefield;
     public InputField usernamefield;
     public InputField passwordfield;
     public InputField passwordhintfield;
     public Dropdown countryField;
     public Dropdown languageField;
     public Text text;
 
 
 
     public Button submitButton;
 
     IEnumerator Start ()
     {

         //Connect to Database and get list of possible player registration countries
         WWW countryRequest = new WWW("http://www.mysite.com/get_country_list.php");
         yield return countryRequest;
         //string[] webResults = countryRequest.text.Split(',');
         List<string> countryList = new List<string>(countryRequest.text.Split(','));
         countryField.AddOptions(countryList);
 
   
         //Connect to Database and get list of possible player languages
         WWW languageRequest = new WWW("http://www.mysite.com/get_language_list.php");
         yield return languageRequest;
         //string[] webResults = languageRequest.text.Split(',');
         List<string> languageList = new List<string>(languageRequest.text.Split(','));
         languageField.AddOptions(languageList);
 
     }
     
 
     public void CallRegister() {
         StartCoroutine(Register());
 
     }
     IEnumerator Register()
     {
 
     
 
         WWWForm form = new WWWForm();
         form.AddField("country", countryField.value);
         form.AddField("language", languageField.value);
         form.AddField("first_name", firstnamefield.text);
         form.AddField("last_name", lastnamefield.text);
         form.AddField("username", usernamefield.text);
         form.AddField("password", passwordfield.text);
         form.AddField("password_hint", passwordhintfield.text);
        
         WWW www = new WWW("http://www.mysite.com/register.php", form);
         yield return www; 
 
      if (www.text == "0")
        {
            Debug.Log("User created succesfully");
            UnityEngine.SceneManagement.SceneManager.LoadScene(0);
         }
       else {
           // THIS IS THE ERROR I AM GETTING WITH NOTHING FROM WWW.TEXT
           Debug.Log("User creation failed. Error #"+ www.text);
       }
 
     }
 
 
 }

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

0 Replies

· Add your reply
  • Sort: 

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

88 People are following this question.

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

Related Questions

How to format data returned from Mysql? 0 Answers

Unity Null Reference Error 1 Answer

Unity PHP login always returning true 3 Answers

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

Necessary Data Rewind Wasn't Possible WWWForm Error 0 Answers


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