garry27 Posted October 15, 2006 Share Posted October 15, 2006 why do i get undefined index variable errors when i run the following script using register_pa() shown further down the page? ???here's an example of the url output:........... [email protected]&pwd=secret&forename=Garry&pwd2=secret&surname=McCabe&gender=m&ta_terms=%09++++&pa_regfrmbtn=Registerand the errors:Notice: Undefined index: email in /home/unn_p921847/public_html/register_pa.php on line 14Notice: Undefined index: pwd in /home/unn_p921847/public_html/register_pa.php on line 15Notice: Undefined index: forename in /home/unn_p921847/public_html/register_pa.php on line 16Notice: Undefined index: pwd2 in /home/unn_p921847/public_html/register_pa.php on line 17Notice: Undefined index: surname in /home/unn_p921847/public_html/register_pa.php on line 18Notice: Undefined index: gender in /home/unn_p921847/public_html/register_pa.php on line 19The password must be at least 6 characters long- please go back and try again.<?php /*****open a session and open function scripts *************************/ session_start(); require_once('common.php'); ///////accesses db_connect() require_once('register_fs.php'); ///////accesses register_pa() //outputs header info to brower with the following title echo xhtmlheader('Error'); //outputs the main navigation bar to the browser //echo topnav_pa(); $email = $_POST['email']; $pwd = $_POST['pwd']; $forename = $_POST['forename']; $pwd2 = $_POST['pwd2']; $surname = $_POST['surname']; $gender = $_POST['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); } echo $email; // 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; } ?><?phpfunction register_pa ($email, $pwd, $forename, $surname, $gender){ //connect to database $conn = db_connect(); try { //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)"); if (!$result) { throw new Exception ('Could not register you in database ' .'- please try again later.'); } } catch (Exception $e) { echo $e->getMessage(); return true; exit; } }much TIA Quote Link to comment https://forums.phpfreaks.com/topic/24005-undefined-index-errors/ Share on other sites More sharing options...
wildteen88 Posted October 15, 2006 Share Posted October 15, 2006 The errors you are getting is becuase of this:[code]$email = $_POST['email']; $pwd = $_POST['pwd']; $forename = $_POST['forename']; $pwd2 = $_POST['pwd2']; $surname = $_POST['surname']; $gender = $_POST['gender'];[/code]You are not using the POST method. You are using the GET method. So you need to use $_GET rather than $_POST Quote Link to comment https://forums.phpfreaks.com/topic/24005-undefined-index-errors/#findComment-109084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.