Firstly i’d like to say that i don’t know if i’m supposed to post this in the PHP section instead but anyway.
Heres the deal, i have a login/register etc functions and i want to use Ajax to “Iframe” one part of the page (the content section) and the thing is that when i click on the button with the onClick function it doesn’t remember anything of the form i just filled…
Is there a way to create a submit function for onClick (because i don’t want to get redirected to the actual registration)
This is the Ajax Function:
[CODE] var klient;
function ajax(filurl) {
klient = new XMLHttpRequest();
klient.onreadystatechange = hanterare;
klient.open(“GET”, filurl);
klient.send(null);
}
function hanterare() {
document.getElementById(“utdata”).innerHTML= klient.responseText;
}
This is the registration form:
[code=html] <form action=”register_ac.php” method=”post”>
Username: <input type=”text” name=”username” size=”20″>
Password: <input type=”password” name=”password” size=”20″>
Email: <input type=”text” name=”email” size=”20″>
<input type=”button” onClick=”ajax(‘register_ac.php’)” value=”Register”>
</form>
And this is the register_ac.php:
[code=php]<?php
include(“config.php”);
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die (“Could not connect to mysql because “.mysql_error());
// select the database
mysql_select_db($database)
or die (“Could not select database because “.mysql_error());
// check if the username is taken
$check = “select id from $table where username = ‘”.$_POST[‘username’].”‘;”;
$qry = mysql_query($check) or die (“Could not match data because “.mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo “Sorry, the username $username is already taken.<br>”;
echo “<a href=index.php>Try again</a>”;
exit;
} else {
// insert the data
$insert = mysql_query(“insert into $table values (‘NULL’, ‘”.$_POST[‘username’].”‘, ‘”.$_POST[’email’].”‘, ‘”.$_POST[‘password’].”‘)”)
or die(“Could not insert data because “.mysql_error());
// print a success message
echo “Your user account has been created!<br>”;
echo “Now you can <a href=index.php>Log in</a>”;
}
?>
Any suggestions?
If you need more just tell me…