because php sends duplicate records to phpMyadmin

1

I have a chat with Flash AS3 i php and I have a Hostinger bd

The chat works fine but sends or receives duplicate records by pressing the Send button.

That is, when I press the send button as you can see in the image, two different ids for the same message come out.

Here below I leave the php code

submitScoreProvaMar.php

<?php

$user = 'u640465832_mar';
$pass = 'xxxxxxxx';
$dbName = 'u640465832_usuar';

$mysqli = new mysqli('mysql.hostinger.es', $user, $pass, $dbName);

if($mysqli->connect_errno)
{
	echo "Failed to connect: " . $mysqli->connect_error;
}

$user		= $_POST['user'];
$missatge 	= $_POST['missatge'];

$query		= "INSERT INTO provaMar (User, Missatge) VALUES ('" . $user . "', '" . $missatge . "')";

$mysqli->query($query);

$result			= $mysqli->query($query);
$returnValue 	= $result->num_rows;

$mysqli->close();

echo $returnValue;

?>

getScoresProvaMar.php

<?php

$user = 'u640465832_mar';
$pass = 'xxxxxxxxxx';
$dbName = 'u640465832_usuar';

$mysqli = new mysqli('mysql.hostinger.es', $user, $pass, $dbName);

if($mysqli->connect_errno)
{
	echo "Failed to connect: " . $mysqli->connect_error;
}


$query = 'SELECT * FROM provaMar ORDER by Datetime DESC limit 10';

$result = $mysqli->query($query);

$returnString = '';

while($row = $result->fetch_assoc())
{
	$returnString .= ($row['Datetime'] . "\n");
	$returnString .= ($row['User'] . ' diu: ' .$row['Missatge']. "\n");

}

echo "returnString=" .$returnString;


?>

and the AS3 code in Flash

He will not let me publish flash code. Flash code AS3

If someone knows why he sent it in duplicate, he will do me a favor Very grateful

    
asked by Mar Archs 15.05.2018 в 11:13
source

1 answer

3

Because in your third capture, you use query() twice.

$mysqli->query($query);//ejecuta insert, éste no hace falta

$result = $mysqli->query($query);//ejecuta insert

Running query ()

  

Make a query to the database.

Since you execute it twice, you do the insert twice.

    
answered by 15.05.2018 в 12:09