Jump to content

need help with script


garry27

Recommended Posts

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.

[code]
<?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);
?>
[/code]



here's my register_fs script:

[code]
<?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;
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/23970-need-help-with-script/
Share on other sites

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-webspace.co.uk/~unn_p921847/[email protected]&pwd=asdfgh&forename=garry&pwd2=asdfgh&surname=mccabe&gender=m&ta_terms=%09++++&pa_regfrmbtn=Register

????????

Link to comment
https://forums.phpfreaks.com/topic/23970-need-help-with-script/#findComment-108922
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.