I have php file which insert the sentence and perform trigger operation as below:
< html > <body >
<?php
$s = $_POST['sent'];
echo "Entered sentence : $s";
if (preg_match_all('/[^=]*=([^;@]*)/', shell_exec("/home/technoworld/Videos/LinSocket/client '$s'"), $matches)) //Values stored in ma.
{
$x = (int) $matches[1][0]; //optionally cast to int
$y = (int) $matches[1][1];
}
$con = mysqli_connect('127.0.0.1:3306', 'root', 'root', 'test');
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: ".mysqli_connect_error();
}
// $sql2 = "CREATE TRIGGER MysqlTrigger AFTER INSERT ON table1 FOR EACH ROW BEGIN INSERT INTO temp1(sent,pindex,nindex) VALUES (NEW.sent,".$x.",".$y.");";
mysqli_query($con,$sql2);
$sql1 = "INSERT INTO table1 (sent)VALUES('$_POST[sent]')";
if (!mysqli_query($con, $sql1)) {
die('Error: '.mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
</html > </body >
And trigger in mysql:
DELIMITER $$
DROP TRIGGER /*!50032 IF EXISTS */ `test`.`MysqlTrigger`$$
CREATE
/*!50017 DEFINER = 'root'@'localhost' */
TRIGGER `MysqlTrigger` AFTER INSERT ON `table1`
FOR EACH ROW BEGIN
INSERT INTO temp VALUES(New.sent,'$x','$y');
END;
$$
DELIMITER ;
I want that $x and $y from test.php should be inserted in database on insert operation. NEW.sent could be inserted in existing code while x and y as 0,0.
If possible then I want to insert sent,x and y from test.php itself on trigger.
I tried it with above test.php removing the comment on trigger part and removing the trigger from mysql database. But it does insert the sentence in table1 only while temp does not get updated.