Jump to content


Photo

need help with script


  • Please log in to reply
4 replies to this topic

#1 garry27

garry27
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 15 October 2006 - 12:06 AM

hi, i'm new to php and this forum so i hope that somone can help me.

i've been stuck on this problem for all day. i'm trying to create a registration feature for a website which i'm practically copying most of it from a book but the script won't work. i get various errors at run-time.

here's my script which is supposed to add a new user (using a function register() available in register_fs.php shown further down the page) to my mysql table which is already created.

<?php  //register_pa.php

  /*****open function scripts and open a session *************************/
  require_once('common.php');
  require_once('register_fs.php');
  session_start();

  //outputs header info to brower with the following title
  echo xhtmlheader('Error');
	
  //outputs the main navigation bar to the browser
  //echo topnav_pa(); 

  $email = $_GET['email'];
  $pwd = $_GET['pwd'];	
  $forename = $_GET['forename'];
  $pwd2 = $_GET['pwd2'];
  $surname = $_GET['surname'];	
  $gender = $_GET['gender'];
 /*  $agree_terms = $_GET['agree_terms']; */
 
  if (!get_magic_quotes_gpc())
    {
	  $email = addslashes($email);
	  $pwd = addslashes($pwd);
	  $forename = addslashes($forename);
	  $surname = addslashes($surname);
	  $gender = addslashes($gender);
	}			
 
  // turn off run-time error notices
  $old_level = error_reporting(E_ALL & ~E_NOTICE);
  
  try
  {
    //checks if all the fields in the form are filled out
    if (!filled_out($_POST))
    {
    throw new Exception("You have not filled the form out correctly"
                        ."- please go back and try again.");
    }
    if ($pwd != $pwd2)
    {
    throw new Exception("The passwords you entered do not match"
                        ."- please go back and try again.");
    }
	
    if (strlen($pwd)<6 || strlen($pwd) >16)
    {
    throw new Exception("The password must be at least 6 characters long"
                        ."- please go back and try again.");
	}
					  
    /****** attempt to register ****************************************************/				  
    register_pa ($email, $pwd, $forename, $surname, $gender);
    $_SESSION['valid_user'] = $email;
  
    echo 'your registration was succesful';
    echo "<br/><br/><a href='pau_home.php'>Go to members page</a>";
	echo xhtmlheader('Registration Completed');
    }
   catch (Exception $e)
  {
     echo $e->getMessage(); 
     exit;
  } 
  
  // revert back to default error report values
  error_reporting(¬£old_level);
?>




here's my register_fs script:

<?php //register_ps.php

function filled_out($form_vars)
{
  // test that each variable has a value
  foreach ($form_vars as $key => $value)
  {
     if (!isset($key) || ($value == '')) 
        return false;
  } 
  return true;
}


function register_pa ($email, $pwd, $forename, $surname, $gender)
{
  //connect to database
  $conn = db_connect();
  
  //check username is unique
  $result = $conn->query("select * from Authourised_User where userEmail='$email'");
  if(!$result)
    throw new Exception('could not execute query');
   
  if($result->num_rows>0)
    throw new Exception ('That e-mail address is already registered with us'
	                     .'- please go back and choose a different one.');	 
						 
  //if ok, put in db
  $result = $conn->query("INSERT into Authourised_User values
                          ('$email', ('$pwd')
						  set userPassword='$pwd'");						  							 
  if (!$result)
    throw new Exception ('Could not register you in database '
	                    .'- please try again later.');

  return true;
}
?>


#2 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 15 October 2006 - 12:35 AM

for the form values i'd use $_POST instead of $_GET.

also session_start should always be first.

it would also help us if you posted what errors you get and maybe even a demo so we can see it for ourselves.

#3 garry27

garry27
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 15 October 2006 - 12:56 AM

hiya, thanks for replying!

i've commented out the exception error statements on the functions page and now I get undefined index errors when i submit the register form:


http://www.nl-webspa...frmbtn=Register

????????



#4 garry27

garry27
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 15 October 2006 - 01:12 PM

help!

#5 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 18 October 2006 - 12:47 AM

thats a notice error.

it's just an non-error error, meaning it wont kill off your program but it will annoy you to death.

I believe there is a way to disable it in your script but i'll have to do some more on that before i do anything more.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users