I have the following structure for registering a new MySQL database account (register.php):
<?php
$con = mysqli_connect("meu_host","meu_user","minha_senha","banco");
mysqli_query($con,"INSERT INTO contas VALUES (" + $id + ", " + $pass + ", '" + $dat + "', '" + $email + "')");
mysqli_close($con);
?>
I have the following elements on my page:
<input type="text" id="ident" />
<input type="password" id="pass" />
<input type="email" id="em" />
<input type="button" onclick="register();" value="Register" name="Reg" />
And the following script embedded in the header
of the page:
<script type="text/javascript">
function register(){
dat = new Date();
id = document.getElementById('ident').value;
pass = document.getElementById('pass').value;
em = document.getElementById('em').value;
<!-- alert("<?PHP register(id,pass,dat,em); ?>"); -->
}
</script>
And my question, what is the best and fastest convention to run the PHP file from a Javascript function? The commented comment was passed to me by a colleague, but it did not work.
Note: The connection to the database is working perfectly.