Jump to content

Recommended Posts

I've been trying to fix this code for a couple of days.It used work but after I tried to add checking for things like account already exists, email already in user, passwords do not match and such it fail to keep working. It does not error out until the end (the query for Char) but the checking seems to not work (can still create two accounts with same name/email and can enter different passwords.

 

<?php
include 'DBopen.php';
$Acc = $_POST['acc'];
$Pwd1 = md5($_POST['pwd1']);
$Pwd2 = md5($_POST['pwd2']);
$Email1 = $_POST['email1'];
$Email2 = $_POST['email2'];
$Class = $_POST['class'];
$Gender = $_POST['gender'];

if ($Pwd1 != $Pwd2){
setcookie('msg','Passwords do not match!',0);
header ( "http://gunners.freehostia.com/CreateAccount.php" );
}

if ($Email1 != $Email2){
setcookie('msg','Emails do not match!',0);
header ( "http://gunners.freehostia.com/CreateAccount.php" );
}

$sql = "SELECT * FROM Player WHERE Acc = '$Acc'";
$result = mysql_query($sql) or die ('Errrrror');
$rows = mysql_num_rows($result);
if ($rows == 1){
setcookie('msg','Account name already in use.',0);
header ( "http://gunners.freehostia.com/CreateAccount.php" );
};


$sql2 = "SELECT * FROM Player WHERE Email = '$Email1'";
$result2 = mysql_query($sql2) or die ('Nope');
$rows1 = mysql_num_rows($result2);
if ($rows2 == 1){
setcookie('msg','Email already in use!',0);
header ( "http://gunners.freehostia.com/CreateAccount.php" );
};
if ($Class = 'class1'){
$Str = 3;
$Int = 3;
$Dex = 2;
};
if ($Class = 'class2'){
$Str = 3;
$Int = 2;
$Dex = 3;
};
if ($Class = 'class3'){
$Str = 3;
$Int = 3;
$Dex = 2;
};
if ($Class = 'class4'){
$Str = 2;
$Int = 3;
$Dex = 2;
};
if ($Class = 'class5'){
$Str = 3;
$Int = 2;
$Dex = 3;
};
if ($Class = 'class6'){
$Str = 2;
$Int = 3;
$Dex = 3;
};
$query = "INSERT INTO Player ( Acc, Pwd, Email, Admin) VALUES ( '$Acc', '$Pwd1', '$Email1', '0')";
mysql_query ($query) or die ('Error you fucked up');

$query2 = "INSERT INTO Char ( Name, Class, Gender, Str, Int, Dex, BStr, BInt, BDex) VALUES ( '$Acc', '$Class', '$Gender', '$Str', '$Int', '$Dex', '0', '0', '0')";
mysql_query ($query2) or die ('Error you fucked up');

setcookie('msg','Account Created!,',0);
//header ("Location: http://gunners.freehostia.com");
echo "$query2";
?>

Thanks in advance.

 

~The Nub~

Link to comment
https://forums.phpfreaks.com/topic/106708-account-creation-help/
Share on other sites

(supposedly) Fixed code:

<?php
include 'DBopen.php';
$Acc = $_POST['acc'];
$Pwd1 = md5($_POST['pwd1']);
$Pwd2 = md5($_POST['pwd2']);
$Email1 = $_POST['email1'];
$Email2 = $_POST['email2'];
$Class = $_POST['class'];
$Gender = $_POST['gender'];

if ($Pwd1 != $Pwd2){
setcookie('msg','Passwords do not match!',0);
header ( "http://gunners.freehostia.com/CreateAccount.php" );
}

if ($Email1 != $Email2){
setcookie('msg','Emails do not match!',0);
header ( "http://gunners.freehostia.com/CreateAccount.php" );
}

$sql = "SELECT * FROM Player WHERE Acc = '$Acc'";
$result = mysql_query($sql) or die ('Errrrror');
$rows = mysql_num_rows($result);
if ($rows == 1){
setcookie('msg','Account name already in use.',0);
header ( "http://gunners.freehostia.com/CreateAccount.php" );
};


$sql2 = "SELECT * FROM Player WHERE Email = '$Email1'";
$result2 = mysql_query($sql2) or die ('Nope');
$rows1 = mysql_num_rows($result2);
if ($rows1 == 1){
setcookie('msg','Email already in use!',0);
header ( "http://gunners.freehostia.com/CreateAccount.php" );
};
if ($Class == 'class1'){
$Str = 3;
$Int = 3;
$Dex = 2;
};
if ($Class == 'class2'){
$Str = 3;
$Int = 2;
$Dex = 3;
};
if ($Class == 'class3'){
$Str = 3;
$Int = 3;
$Dex = 2;
};
if ($Class == 'class4'){
$Str = 2;
$Int = 3;
$Dex = 2;
};
if ($Class == 'class5'){
$Str = 3;
$Int = 2;
$Dex = 3;
};
if ($Class == 'class6'){
$Str = 2;
$Int = 3;
$Dex = 3;
};
$query = "INSERT INTO Player ( Acc, Pwd, Email, Admin) VALUES ( '$Acc', '$Pwd1', '$Email1', '0')";
mysql_query ($query) or die ('Error you fucked up');

$query2 = "INSERT INTO Char ( Name, Class, Gender, Str, Int, Dex, BStr, BInt, BDex) VALUES ( '$Acc', '$Class', '$Gender', '$Str', '$Int', '$Dex', '0', '0', '0')";
mysql_query ($query2) or die ('Error you fucked up');

setcookie('msg','Account Created!,',0);
//header ("Location: http://gunners.freehostia.com");
echo "$query2";
?>

After changing the error checking to something useful this is what I'm getting.

 

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Char ( Name, Class, Gender, Str, Int, Dex, BStr, BInt, BDex) VAL

 

Any ideas?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.