whitevo
Feeling good, thats what I do.
I tried to combine creating an account and character in Znote AAC, but I get error.
I don't know nothing about SQL, PHP nor HTML, no clue what does this error mean.
My register.php looks like this:
I don't know nothing about SQL, PHP nor HTML, no clue what does this error mean.
Code:
1string(594) "INSERT INTO `players`(`name`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `save`, `skull`, `skulltime`, `lastlogout`, `blessings`, `balance`) VALUES ('test2', '1', '', '1', '0', '1000', '1000', '0', '68', '76', '78', '58', '128', '0', '0', '500', '500', '0', '100', '1', '5', '5', '2', '', '1000', '1', '0', '', '1', '0', '0', '0', '0', '0');"
(query - SQL error)
Type: voidQuery (voidQuery is used for update, insert or delete from database)
Cannot add or update a child row: a foreign key constraint fails (`whiserv`.`players`, CONSTRAINT `players_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE)
My register.php looks like this:
Code:
<?php
require_once 'engine/init.php';
logged_in_redirect();
include 'layout/overall/header.php';
if (empty($_POST) === false) {
// $_POST['']
$required_fields = array('username', 'password', 'password_again');
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'You need to fill in all fields.';
break 1;
}
}
// check errors (= user exist, pass long enough
if (empty($errors) === true) {
/* Token used for cross site scripting security */
if (!Token::isValid($_POST['token'])) {
$errors[] = 'Token is invalid.';
}
if ($config['use_captcha']) {
include_once 'captcha/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
$errors[] = 'Captcha image verification was submitted wrong.';
}
}
if (user_exist($_POST['username']) === true) {
$errors[] = 'Sorry, that username already exist.';
}
// Don't allow "default admin names in config.php" access to register.
$isNoob = in_array(strtolower($_POST['username']), $config['page_admin_access']) ? true : false;
if ($isNoob) {
$errors[] = 'This account name is blocked for registration.';
}
if (strtolower($_POST['username']) === true) {
$errors[] = 'Sorry, that username already exist.';
}
if (preg_match("/^[a-zA-Z0-9]+$/", $_POST['username']) == false) {
$errors[] = 'Your account name can only contain characters a-z, A-Z and 0-9.';
}
// name restriction
$resname = explode(" ", $_POST['username']);
foreach($resname as $res) {
if(in_array(strtolower($res), $config['invalidNameTags'])) {
$errors[] = 'Your username contains a restricted word.';
}
else if(strlen($res) == 1) {
$errors[] = 'Too short words in your name.';
}
}
// end name restriction
if (strlen($_POST['password']) < 6) {
$errors[] = 'Your password must be at least 6 characters.';
}
if (strlen($_POST['password']) > 100) {
$errors[] = 'Your password must be less than 100 characters.';
}
if ($_POST['password'] !== $_POST['password_again']) {
$errors[] = 'Your passwords do not match.';
}
if (validate_ip(getIP()) === false && $config['validate_IP'] === true) {
$errors[] = 'Failed to recognize your IP address. (Not a valid IPv4 address).';
}
}
}
?>
<h1>Register Account</h1>
<?php
if (isset($_GET['success']) && empty($_GET['success'])) {
echo 'Congratulations! Your account has been created. You can now login to game.(you get the client in downloads)';
} elseif (isset($_GET['authenticate']) && empty($_GET['authenticate'])) {
// Authenticate user, fetch user id and activation key
$auid = (isset($_GET['u']) && (int)$_GET['u'] > 0) ? (int)$_GET['u'] : false;
$akey = (isset($_GET['k']) && (int)$_GET['k'] > 0) ? (int)$_GET['k'] : false;
// Find a match
$user = mysql_select_single("SELECT `id` FROM `znote_accounts` WHERE `account_id`='$auid' AND `activekey`='$akey' AND `active`='0' LIMIT 1;");
if ($user !== false) {
$user = $user['id'];
// Enable the account to login
mysql_update("UPDATE `znote_accounts` SET `active`='1' WHERE `id`='$user' LIMIT 1;");
echo '<h1>Congratulations!</h1> <p>Your account has been created. You can now login to game.(you get the client in downloads)</p>';
} else {
echo '<h1>Authentication failed</h1> <p>Either the activation link is wrong, or your account is already activated.</p>';
}
} else {
if (empty($_POST) === false && empty($errors) === true) {
if ($config['log_ip']) {
znote_visitor_insert_detailed_data(1);
}
//Register
$register_data = array(
'name' => $_POST['username'],
'password' => $_POST['password'],
'ip' => ip2long(getIP()),
'created' => time()
);
user_create_account($register_data, $config['mailserver']);
$character_data = array(
'name' => $_POST['username'],
'account_id'=> $session_user_id,
'vocation' => 0,
'town_id' => 1,
'sex' => $_POST['selected_gender'],
'lastip' => ip2long(getIP()),
'created' => time()
);
user_create_character($character_data);
if (!$config['mailserver']['debug']) header('Location: register.php?success');
exit();
//End register
} else if (empty($errors) === false){
echo '<font color="red"><b>';
echo output_errors($errors);
echo '</b></font>';
}
?>
<form action="" method="post">
<ul>
<li>
Character Name:<br>
<input type="text" name="username">
</li>
<li>
Password:<br>
<input type="password" name="password">
</li>
<li>
Password again:<br>
<input type="password" name="password_again">
</li>
<li>
<!-- Available genders to select from when creating character -->
Gender:<br>
<select name="selected_gender">
<option value="1">Male</option>
<option value="0">Female</option>
</select>
</li>
<?php
if ($config['use_captcha']) {
?>
<li>
<b>Write the image symbols in the text field to verify that you are a human:</b>
<img id="captcha" src="captcha/securimage_show.php" alt="CAPTCHA Image" /><br>
<input type="text" name="captcha_code" size="10" maxlength="6" />
<a href="#" onclick="document.getElementById('captcha').src = 'captcha/securimage_show.php?' + Math.random(); return false">[ Different Image ]</a><br><br>
</li>
<?php
}
?>
<?php
/* Form file */
Token::create();
?>
<li>
<input type="submit" value="Create Account">
</li>
</ul>
</form>
<?php
}
include 'layout/overall/footer.php';
?>