Jump to content

Calling Custom Functions Problem


Recommended Posts

So me and my team of developers are creating a web based flash game, and I've been working on the register page. Thing is, I can't get it to submit the given information to the database. I think it may be something to do with my functions, since this is the first I've worked heavily with them. *EDIT* I added in the whole page incase there was some confusion

 

<?php
$name = $_POST['name'];					//Get Name
$password = $_POST['password'];			//Get Password
$ppassword = $_POST['ppassword'];		//Get Repeated Password
$username = $_POST['username'];			//Get Username
$email = $_POST['email'];				//Get Email
$age = $_POST['age'];					//Get Age
$hashname = (md5($hash . $name));		//Hash Name
$hashpw = (md5($hash . $password));		//Hash Password
$checkcont = file('blocked.txt');		//Blocked User Input Content

function Register(){ 					// Insert Function
/* Create User Login Account*/      mysql_query("INSERT INTO accounts ( name , password , username , email , age ) VALUES ( $name , $password , $username , $email, $age )");
/* Create User Character Field 1 */ mysql_query("INSERT INTO users ( chr , password , username ,  slot , auth , exp , money , name ) VALUES ( 'null' , $hashpw , $username , 1 , 1 , 'null' , 'null' , $hashname)");
/* Create User Character Field 2 */ mysql_query("INSERT INTO users ( chr , password , username ,  slot , auth , exp , money , name ) VALUES ( 'null' , $hashpw , $username , 2 , 1 , 'null' , 'null' , $hashname)");
/* Create User Character Field 3 */ mysql_query("INSERT INTO users ( chr , password , username ,  slot , auth , exp , money , name ) VALUES ( 'null' , $hashpw , $username , 3 , 1 , 'null' , 'null' , $hashname)");
}

function Email(){						//Create & Send Email Link

}

function CheckInput(){					//Check User Input
$errors = 0;							//Set Errors Null
$swears = 0;							//Set Swears Null
$notos = 0;								//Set TOS Null

if($name !== null){
	if($name !== $checkcont){
		if($password !== null){
			if($password !== $checkcont){
				if($ppassword !== null){
					if($username !== null){
						if($username !== $checkcont){
							if($email !== null){
								if(isset($_POST['tos'])){
									if($age !== null){
										Register();
									}else{ $errors++; }
								}else{ $notos = 1; }
							}else{ $errors++; }
						}else{ $swears++; }
					}else{ $errors++; }
				}else{ $errors++; }
			}else{ $swears++; }
		}else{ $errors++; }
	}else{ $swears++; }
}else{ $errors++; }
}

if(isset($_POST['submit'])){
CheckInput();
}
?>
<?php
  $browser = array(
    'version'   => '0.0.0',
    'majorver'  => 0,
    'minorver'  => 0,
    'build'     => 0,
    'name'      => 'unknown',
    'useragent' => ''
  );

  $browsers = array(
    'firefox', 'msie', 'opera', 'chrome', 'safari', 'mozilla', 'seamonkey', 'konqueror', 'netscape',
    'gecko', 'navigator', 'mosaic', 'lynx', 'amaya', 'omniweb', 'avant', 'camino', 'flock', 'aol'
  );

  if (isset($_SERVER['HTTP_USER_AGENT'])) {
    $browser['useragent'] = $_SERVER['HTTP_USER_AGENT'];
    $user_agent = strtolower($browser['useragent']);
    foreach($browsers as $_browser) {
      if (preg_match("/($_browser)[\/ ]?([0-9.]*)/", $user_agent, $match)) {
        $browser['name'] = $match[1];
        $browser['version'] = $match[2];
        @list($browser['majorver'], $browser['minorver'], $browser['build']) = explode('.', $browser['version']);
        break;
      }
    }
  }
?>
<html>
<!-- This Is Our Header -->
<head>
	<script>	
		function getbrowser(){
			open = window.open("getbrowser.php", "open", "location=1,status=1,scrollbars=1,  width=300,height=300");
			open.moveTo(0, 0);
		}
	</script>
	<title>
		The Dragon Seige™ Register
	</title>
	<?php 
		if($browser['name'] == "chrome"){
			$using = 1;
			echo "<link href=\"styles/chromereg.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\" />";
		}elseif($browser['name'] == "firefox"){
			$using = 2;
			echo "<link href=\"styles/firefoxreg.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\" />";
		}
		if(($using !== 1) && ($using !== 2)){
			echo "";
		}
	?>
</head>
  <!-- This Ends Our Header -->
  
  <!-- This Is Our Body -->
<body>
<?php
if(($using == 1) || ($using == 2)){?>

<div id="registerwrap">
		<?php 
			include('inc/header.php');
		?>

	<div class="content">
		<center>
			<div id="registercont">
				<h2>
					Registration
				</h2>
				<hr width="99.9%" color="red" size="5px" />

				<?php 
					if($errors > 0){ 	//If Errors, Make Aware
						echo "There are errors on your registration.<br/>";}
					if($swears > 0){	//If Swears, Make Aware
						echo "Please do not use inappropriate content.<br/>";}
					if($notos > 0){		//If NoTos, Make Aware
						echo "Please accept the Terms Of Service.<br/>";}
				?>

				<form action="" method="post">
                    <fieldset>
                    <legend>Personal / Login Information</legend>
					<table width="98%">
						<tr>
							<td width="49%">Name:[Full Name]</td>
							<td width="49%"><input type="text" style="width: 98%;" name="name" id="name"></td>
						</tr>
						<tr>
							<td>Password:<br/>[6-30 Characters]</td>
							<td><input type="password" style="width: 98%;" name="password" id="password"></td>
						</tr>
						<tr>
							<td>Re-Enter Password:</td>
							<td><input type="password" style="width: 98%;" name="ppassword" id="ppassword"></td>
						</tr>
						<tr>
							<td>Username:<br/>[Login Name]</td>
							<td><input type="text" style="width: 98%;" name="username" id="username"></td>
						</tr>
						<tr>
							<td>e-Mail:[Activation]</td>
							<td><input type="email" style="width: 98%;" name="email" id="email"></td>
						</tr>
						<tr>
							<td>Age:[For Content]</td>
							<td><select name="age" id="age" style="width:98%;">
								<option value="noage" id="noage" name="noage">Select Age</option>

								<?php
								$age = 13;	
									while($age < 41){	//Make Age Field
										echo "<option value=\"$age\">" . $age . "</option>";
										$age++;
									}
								?>
								<option value="other" id="other" name="other">Older</option>
							</td>
						</tr>
					</table>
                        </fieldset>
					<p align="left">By agreeing to these terms of service, you hereby agree that you are either of legal age, or have consent of a parent and/or guardian, to view and play this game. You agree to abide by the rules of the game, along with being respectful to all players. You understand that the proper consequences will be taken against you if you break any rule of the game, or break the terms of service.</p>
					<div id="tos">	
						<table width="100%">
							<tr>
								<td width="85%">I Understand And Agree To The Terms Of Service.</td>
								<td width="5%"><input type="checkbox" style="margin-top:2px;" name="tos" id="tos" /></td>
							</tr>
						</table>
					</div>	
						<br/>
					<input type="submit" style="background-color: white;" value="Register" name="Register" id="Register" />
				</form>			
			</div>
		</center>
		<?php
			include('inc/footer.php');
		?>
	</div>
</div>
<?php
}else{
?>
<body onload="getbrowser()">
<?php }
?>
</body>
  <!-- This Ends Our Body -->
</html>

Now, I'm no expert at PHP, but I honestly don't understand why this isn't working. Can anyone give me some tips? Thanks!

Link to comment
Share on other sites

1. Are you getting any errors/warnings?

 

2. Are you actually connecting to the db?

 

3. Have you manually tested your queries?

 

I am getting no errors, nothing is happening. It's like the submit button isn't being checked. I am connecting to the database. I have used the queries on another script to test them.

Link to comment
Share on other sites

You need to set php's error_reporting to E_ALL and display_errors to ON in your master php.ini to get php to help you. Stop and start your web server to get any changes made to your master php.ini to take effect and use a phpinfo statement to confirm that the settings got changed in case the php.ini that php is using is not the one that you changed. Just about all the variables that are inside of your various functions don't exist in the scope where you are using them.

Link to comment
Share on other sites

You need to set php's error_reporting to E_ALL and display_errors to ON in your master php.ini to get php to help you. Stop and start your web server to get any changes made to your master php.ini to take effect and use a phpinfo statement to confirm that the settings got changed in case the php.ini that php is using is not the one that you changed. Just about all the variables that are inside of your various functions don't exist in the scope where you are using them.

 

So I did that, and got a "unknown variable" blah blah, and fixed that by placing all of my POST checks into a function and calling it inside of my CheckInput function, but I'm still getting the error.

Link to comment
Share on other sites

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.