0

I am using the code I have attached to insert a record into my Users table on my MYSQL database, the code works fine but it is inserting two records each time I create a user. I am not sure why as I am only inserting once in the code (or at-least I think so). Maybe someone has ran into a similar issue?

<?php
$username = $_GET["username"];
$password = $_GET["password"];

$con=mysqli_connect("localhost","pluginconnect","","UAPlugin");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
mysqli_select_db($con,"UAPlugin");

$result = mysqli_query($con,"INSERT INTO UAPlugin_Login (username, password)
VALUES ('$username', '$password')");

$jsonResponse = array("UAPlugin" => array());
if(!$result)
{
    die('Could not enter data: ' . mysql_error());
     $jsonRow = array(
             "success"=>"0",
            "message"=>"Account Not Created");
    array_push($jsonResponse["UAPlugin"],$jsonRow);
}
else
{
     $jsonRow = array(
             "success"=>"1",
            "message"=>"Account Created");
    array_push($jsonResponse["UAPlugin"],$jsonRow);
}

echo json_encode($jsonResponse);

?>
3
  • Sorry, but you should really start over, there is just too much wrong here: Sql injection, plain-text passwords both in the database and in the url / browser history and no unique constraints / checks on the username to start with. Commented Apr 8, 2019 at 9:49
  • Then your form is submitting two times or hitting this file two time, check and fix that. Another way before inserting check that username and password are exist with same combination. Commented Apr 8, 2019 at 9:51
  • 1.don't send username and password in query-string. 2.Don't save plain password (SQL INJECTION possible). 3 You have to apply uniqueness for username otherwise how can you compare that which password belong to which user if in case two usernames are same. Commented Apr 8, 2019 at 9:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.