7
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 next script embedded in the header
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 comado was passed to me by a colleague, but it didn’t work.
Note: the connection to the database is working perfectly.
How could you post the current system date instead of one defined in form?
– Guill
+1
- it would be interesting to put an example with vanilla since the question has no jQuery tag– Sergio
I did exactly as in the reply, and the record was not entered. Once the page is updated, I cannot see the results of the Echos for debug. Idea?
– Guill
@Guill, if you use firefox install a javascript Debugger like firebug to see the return of ajax. In Alert nothing appears?
– rray
@lost Chrome usage. Nothing appears. Just refresh the page and display the form values in the url, including the password... One detail: in the database my password field is of the whole type, so I replaced "isss" with "iiss". I did it correctly?
– Guill
Press F12 on Chrome, and run the code again, see if an error appears on the console.
– rray
"GET http://giproductions.byethost24.com/jquery-1.10.1.js 404 (Not Found)" It looks like I need to import the jQuery lib to the FTP server.
– Guill
I imported the jQuery and it worked. Like the tag jQuery is not part of the question, I ask you to write in the answer, that you need to have the file "jquery-1.10.1.js" in the page folder.
– Guill