Okay thanks i got it to work on the php side, but then now is a new question.
How do I create a form for HTML and linked it with php. like instead ofhave a new page wit no background on the php side, I want it to be able to just successful registered on the html side.
Also i know there has to be with something like
<form method="post" action='register.php'>
user:
pass:
email:
</form>
Quote:
Originally Posted by HeartlessBoiYang
Okay thanks i got it to work on the php side, but then now is a new question.
How do I create a form for HTML and linked it with php. like instead ofhave a new page wit no background on the php side, I want it to be able to just successful registered on the html side.
|
my html file for register page:
<script src="http://code.jquery.com/jquery-lastest.js"></script>
<script src="js/submit.js"></script>
<font size="5" color="#99cc33"><b>Create an Account </b></font>
<br />
<form id="myForm" method="post">
<br />
Username :<br />
<input name="account" type="text" class="input" id="account" value="" onclick="if (account.value == 'Account Name...') { account.value='' }" onfocus="account.id='focused'" onblur="account.id='unfocused'" style="margin-bottom: 7px;" maxlength="23"/>
<br />
Password :<br />
<input name="password" type="password" class="input" id="password" value="" onclick="if (password.value == 'Password...') { password.value='' }" onfocus="password.id='focused'" onblur="password.id='unfocused'" style="margin-bottom: 7px;" maxlength="23"/>
<br />
Re-type Password :<br />
<input name="passwordchk" type="password" class="input" id="passwordchk" value="" onclick="if (passwordchk.value == 'password...') { passwordchk.value='' }" onfocus="passwordchk.id='focused'" onblur="passwordchk.id='unfocused'" style="margin-bottom: 7px;" maxlength="23"/>
<br />
Email :<br />
<input name="email" type="text" class="input" id="email" value="" onclick="if (email.value == 'Email...') { email.value='' }" onfocus="email.id='focused'" onblur="email.id='unfocused'" style="margin-bottom: 7px;" maxlength="41"/>
<br />
Security Question :<br />
<select name="secquestion" class="input" id="secquestion" style="margin-bottom:7px;">
<option value="" selected="selected">-Select Secret Question-</option>
<option value="What is the first name of your favorite uncle?" >What is the first name of your favorite uncle?</option>
<option value="Where did you meet your spouse?" >Where did you meet your spouse?</option>
<option value="What is your oldest cousins name?" >What is your oldest cousins name?</option>
<option value="What is your youngest childs nickname?" >What is your youngest childs nickname?</option>
<option value="What is your oldest childs nickname?" >What is your oldest childs nickname?</option>
<option value="What is the first name of your oldest niece?" >What is the first name of your oldest niece?</option>
<option value="What is the first name of your oldest nephew?" >What is the first name of your oldest nephew?</option>
<option value="What is the first name of your favorite aunt?" >What is the first name of your favorite aunt?</option>
<option value="Where did you spend your honeymoon?" >Where did you spend your honeymoon?</option>
</select>
<br />
Answer :<br />
<input name="answer" type="text" class="input" id="answer" value="" onclick="if (answer.value == 'Answer...') { answer.value='' }" onfocus="answer.id='focused'" onblur="answer.id='unfocused'" style="margin-bottom: 7px;" maxlength="22"/>
<br />
<input name="register" type="submit" class="enter" id="register" onclick="action()" value="Submit" />
<script>
function action() {
//Your code here
}
</script>
</form>
<div id="result">
</div>
register php code:
<?php
$hostname_localhost = "localhost";
$database_localhost = "cq";
$username_localhost = "root";
$password_localhost = "123456789";
$localhost = mysql_connect($hostname_localhost, $username_localhost, $password_localhost) or die("MYSQL Cannot Connect");
mysql_select_db($database_localhost) or die("Database doesnt exist");
function isValidEmail($value){
$pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
return preg_match($pattern, $value);
}
//error_reporting(0);
if(isset($_POST['register']))
{
$acc = mysql_escape_string($_POST['account']);
$pass = mysql_escape_string($_POST['password']);
$passchk = mysql_escape_string($_POST['passwordchk']);
$answer = mysql_escape_string($_POST['answer']);
if(!empty($acc) && !empty($pass) && !empty($_POST['email']) && !empty($_POST['secquestion']) && !empty($answer))
{
if(strlen($acc) < 23 && strlen($acc) > 3 && strlen($pass) < 23 && strlen($pass) > 3 && $pass == $passchk)
{
if(isValidEmail($_POST['email']) && strlen($_POST['email']) < 41)
{
if(strlen($answer) < 22 && $_POST['secquestion'] != '')
{
$check = mysql_query("SELECT * FROM accounts WHERE username = '".$acc."' ") or die("MYSQL Select From Accounts Error");
$rows = mysql_num_rows($check);
if($rows == 0)
{
mysql_query("INSERT INTO accounts (Username, Password, Email, question, answer) VALUES ('".$acc."', '".$pass."', '".$_POST['email']."', '".$_POST['secquestion']."', '".$answer."')");
echo("<br /><center>Username <i>'".$acc."'</i> successfully created</center>");
}
else
{
die("<br /><center>Username <i>'".$acc."'</i> is already registered, please use another name.</center>");
}
}
else
{
die("<br /><center>The answer provided for the question was to long, please try again.</center>");
}
}
else
{
die("<br /><center>Email Address is either to long, or not setup right, please try again.</center>");
}
}
else
{
die("<br /><center>You're Lengths for Username and or Password is to long/short, or failed to pass password check</center>");
}
}
else
{
die("<br /><center>One or more fields missing, please try again.</center>");
}
}
mysql_close($localhost);
?>
and my .ja file, trying to make the submit form without redirect to a new tab(white page said Successfully registered!)
<script>
$(document).ready(function () {
$('.register').click(function (e) {
e.preventDefault();
var account = $('#account').val();
var password = $('#password').val();
var email = $('#email').val();
var secquestion = $('#secquestion').val();
var answer = $('#answer').val();
({
type: "GET",
url: "register.php",
data: { "account": account, "password": password, "email": email, "secquestion": secquestion, "answer": answer },
success: function (data) {
$('.result').html(data);
$('#myForm')[0].reset();
}
});
});
});
</script>
so please tell me if i did anything wrong here...