Jump to content

Include fuction


eadc

Recommended Posts

Hi there,

I've been working on a user management system and every time I run the user_add.php page it stops right after it has done almost all of the work. It stops right before a "Include" function which is suppose to bring you back to the main user page. Can some one please tell me why is this "Include" function not working? It stops after showing : "<< User Added Successfully >>. Here is the code:

==========================

 

<?

include ('config.php');

include ('verify.php');

require('global.php');

 

if(isset($_POST['submit']))

{

  $_POST['firstname'] = ucwords(strtolower($_POST['firstname']));

  $_POST['lastname'] = ucwords(strtolower($_POST['lastname']));

  if(!validate_email_address($_POST['wemail'])){

          $errors[] = 'The company email address you entered was invalid.';

            }

  if(!validate_email_address($_POST['hemail'])){

$errors[] = 'The home email address you entered was invalid.';

}

  if(!validate_name($_POST['firstname'])){

$errors[] = 'Please enter a first name between 1 and 15 characters.';

    }

  if(!validate_name($_POST['lastname'])){

$errors[] = 'Please enter a last name between 1 and 15 characters.';

}

  if(!validate_username($_POST['username'])){

$errors[] = 'The username must be alphanumeric and 5-15 characters long.';

    }

  if(check_email_exists($_POST['wemail'])){

$errors[] = 'The company email address you entered already exists for another user.';

      }

  if(check_email_exists($_POST['hemail'])){

$errors[] = 'The home email address you entered already exists for another user.';

      }

  if(strlen($_POST['wemail']) > 60){

$errors[] = 'Please enter an company email that is no longer than 60 characters.';

    }

  if(strlen($_POST['hemail']) > 60){

$errors[] = 'Please enter an home email that is no longer than 60 characters.';

    }

  if(!validate_password($_POST['password'])){

$errors[] = 'For maximum security, your password must be between 6 and 10 characters long, and it must contain at least one letter and one number.';

}

  if(check_user_exists($_POST['username'])){

$errors[] = 'The username you have selected is already taken. Please choose a new one.';

    }

 

// Validate uniqueness of Username

//$q = mysql_query("select * from users WHERE username = '$_POST[username]';");

//while($f=mysql_fetch_array($q))

//{Echo "<P class='ErrorRed'>Username ".$_POST[username]." already exist!</p>";

//Echo "<p>Go <a href='index.#'>Back</a> and try another username.</p>";}

 

  //} // End of Validation session

 

  // THIS SECTION FOLLOWS IF NO ERRORS WERE FOUND

  if(empty($errors)){

 

// Convert date in mysql format

$year = $_POST[year];

$month = $_POST[month];

$day = $_POST[day];

$birthday = $year . "-" . $month . "-" . $day;

 

if ($_POST[password] == "")

{

function createRandomPassword() {

 

    $chars = "abcdefghijkmnopqrstuvwxyz023456789";

    srand((double)microtime()*1000000);

    $i = 0;

    $pass = '' ;

 

    while ($i <= 7) {

        $num = rand() % 33;

        $tmp = substr($chars, $num, 1);

        $pass = $pass . $tmp;

        $i++;

    }

 

    return $pass;

}

 

// Usage

$password = createRandomPassword();

//echo "Your random password is: $password";

}

else

{$password = $_POST[password];}

 

 

$adduser[] = "INSERT INTO users SET

firstname = '$_POST[firstname]',

lastname = '$_POST[lastname]',

username = '$_POST[username]',

password = '$password',

company = '$_POST[company]',

birthday = '$birthday',

position = '$_POST[position]',

waddress = '$_POST[waddress]',

haddress = '$_POST[haddress]',

workphone = '$_POST[workphone]',

homephone = '$_POST[homephone]',

fax = '$_POST[fax]',

cel = '$_POST[cel]',

wemail = '$_POST[wemail]',

hemail = '$_POST[hemail]',

notes = '$_POST[notes]'";

 

while (list($var, $val) = each($adduser))

{

$query = mysql_query($val);

IF (!$query)

{

echo ("$var: " . mysql_error());

exit();

}

}

 

////////// Send new user an e-mail using his/her ///////////////////////////////////////////////////////////

if ($_POST[wemail] == "")

{$user_email = $_POST[hemail];}

else

{$user_email = $_POST[wemail];}

 

// create and send notify mail message

$msg =  "Dear $_POST[firstname], \n\n";

$msg .= "This e-mail is to notify you that a user account has been created for you on www.xxxxxx.com/members.\n\n";

$msg .= "Click on above link and log-in to your account to enjoy all the features of xxxx Online.\n\n";

$msg .= "==============================================================================\n\n";

$msg .= "Your username is: $_POST[username]\n";

$msg .= "Your password is: $password\n";

$msg .= "==============================================================================\n\n";

$msg .= "Kind regards,\n\n";

$msg .= "Website Admin\n\n";

 

 

 

If(!mail($user_email, "MEMBER ACCOUNT", $msg, "From: xxxx@xxxxx.com")){

 

Exit("There was a problem sending your message. Please try again later.\n");

 

} Else {

 

$sent_mail=true;

 

}

 

$message = "<< User Added Successfully >>";

echo $message;

//include ('userr.php');

include ('user.php'); //THIS IS THE TROUBLE INCLUDE FUNCTION!!

//echo "INCLUDE HERE";

exit;

} // END OF NO ERRORS FOUND

 

} // END OF SUBMIT

?>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Add User Area</title>

</head>

 

<body>

<h1>Add New Member </h1>

 

<?

  if (!empty($errors)){ echo "<BR>"; ?><table width="95%" height="24" border="0" align="center">

      <tr>

        <td height="20">

<div class="ErrorRed"><ul>

<?php

foreach($errors as $error){

print '<li>'.$error.'</li>';

}

?>

</ul></div></td>

      </tr>

    </table>

      <? } else { print '<br />'; } ?>

     

<p>Fields with [*] are required fields. </p>

<form name="form1" method="post" action="" onSubmit="return validateStandard(this, 'error');">

  <table width="100%"  border="0">

    <tr>

      <td width="17%"> </td>

      <td width="37%" class="NormalText">First Name,  Last Name</td>

      <td width="16%"> </td>

      <td width="27%"> </td>

    </tr>

    <tr>

      <td><div align="right" class="FormTitleText">Name [*]: </div></td>

      <td><input name="firstname" type="text" id="firstname" size="20" maxlength="30" required="1" regexp="/^\w*$/" <? if(isset($_POST['firstname'])) print ' value="'.$_POST['firstname'].'"'; ?>>

          <input name="lastname" type="text" id="lastname" size="20" maxlength="32" required="1" regexp="/^\w*$/" <? if(isset($_POST['lastname'])) print ' value="'.$_POST['lastname'].'"'; ?>></td>

      <td class="FormTitleText"><div align="right">Home Address :</div></td>

      <td><input name="haddress" type="text" id="haddress" size="30" maxlength="30"></td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right">Company:</div></td>

      <td><input name="company" type="text" id="company" size="45" maxlength="50"></td>

      <td class="FormTitleText"><div align="right">Birthday:</div></td>

      <td><label>

        <select name="month" id="month">

        <?PHP

// Put months of the year/////////////

$bdaymonth=array("1"=>"Jan","2"=>"Feb","3"=>"Mar","4"=>"Apr","5"=>"May","6"=>"Jun","7"=>"Jul","8"=>"Aug","9"=>"Sep","10"=>"Oct","11"=>"Nov","12"=>"Dec");

foreach($bdaymonth as $key => $value){

        echo "<option value=".$key.">" . $value."</option>";

        }

  ?>

        </select>

        <select name="day" id="day">

          <?PHP

  // Put days of the month////////

  for ($i = 1; $i <= 31; $i++) {

          echo "<option value=".$i.">".$i."</option>";

  }

  ?>

        </select>

         

        <select name="year" id="year">

<?PHP

// Put acceptable birth years /////////////////

$currentyear = date("Y");

echo $currentyear;

$maxyear = $currentyear - 90;

$minyear = $currentyear - 18;

 

for ($i = $maxyear; $i <= $minyear; $i++) {

        echo "<option value=".$i.">".$i."</option>";

          }

?>

        </select>

      </label></td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right"> Position:</div></td>

      <td><input name="position" type="text" id="position" size="45" maxlength="30"></td>

      <td class="FormTitleText"> </td>

      <td> </td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right"> Company Address:</div></td>

      <td><input name="waddress" type="text" id="waddress" size="45" maxlength="30"></td>

      <td class="FormTitleText"> </td>

      <td> </td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right">Company Phone:</div></td>

      <td><input name="workphone" type="text" id="workphone" size="30" maxlength="15"></td>

      <td class="FormTitleText"><div align="right">Home Phone:</div></td>

      <td><input name="homephone" type="text" id="homephone" size="30" maxlength="15"></td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right">Company Fax:</div></td>

      <td><input name="fax" type="text" id="fax" size="30" maxlength="15"></td>

      <td class="FormTitleText"><div align="right">Cel Phone :</div></td>

      <td><input name="cel" type="text" id="cel" size="30" maxlength="15"></td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right">Company E-mail [*]:</div></td>

      <td><input name="wemail" type="text" id="wemail" size="45" maxlength="50" required="1" regexp="/^\w*$/" <? if(isset($_POST['wemail'])) print ' value="'.$_POST['wemail'].'"'; ?>></td>

      <td class="FormTitleText"><div align="right">Personal E-mail :</div></td>

      <td><input name="hemail" type="text" id="hemail" size="45" maxlength="50" <? if(isset($_POST['hemail'])) print ' value="'.$_POST['hemail'].'"'; ?>></td>

    </tr>

    <tr>

      <td class="FormTitleText"> </td>

      <td> </td>

      <td> </td>

      <td> </td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right">Username [*]:</div></td>

      <td><input name="username" type="text" id="username" size="30" maxlength="30" required="1" regexp="/^\w*$/" <? if(isset($_POST['username'])) print ' value="'.$_POST['username'].'"'; ?>></td>

      <td> </td>

      <td> </td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right">Password:</div></td>

      <td><input name="password" type="Password" id="password" size="30" maxlength="10">

        <span class="style1">*</span></td>

      <td> </td>

      <td> </td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right">Re-type Password:</div></td>

      <td><input name="password2" type="Password" id="password2" equals="password" err="The two password fields are not the same. Please retype both password fields exactly the same." size="30" maxlength="10">

          <span class="style1">*</span></td>

      <td> </td>

      <td> </td>

    </tr>

    <tr>

      <td class="FormTitleText"> </td>

      <td> </td>

      <td> </td>

      <td> </td>

    </tr>

    <tr>

      <td class="FormTitleText"><div align="right">Notes:</div></td>

      <td><textarea name="notes" cols="35" rows="5" wrap=virtual></textarea>

      <td> 

    <td>    </tr>

    <tr>

      <td> </td>

      <td><input name="submit" type="submit" class="FormButton" id="submit" value="Add Member"></td>

      <td> </td>

      <td> </td>

    </tr>

  </table>

</form>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td colspan="2" valign="top" bgcolor="#CCCCCC"><img src="img/1x1trans.gif" width="1" height="1"></td>

  </tr>

  <tr>

    <td valign="top"> </td>

    <td> </td>

  </tr>

  <tr>

    <td width="31" valign="top"><div align="center" class="ErrorRed">      *</div></td>

    <td width="769"><p class="ErrorRed">Type a password or leave empty and a password will be created for this member. When you add the member to the AHRA database the password will be send to his/her Company E-mail address. </p></td>

  </tr>

  <tr>

    <td> </td>

    <td> </td>

  </tr>

  <tr>

    <td> </td>

    <td> </td>

  </tr>

  <tr>

    <td> </td>

    <td> </td>

  </tr>

</table>

<p> </p>

</body>

</html>

Link to comment
Share on other sites

Yes, I've tried that and now it seems that the problem starts after the "include ('config.php')".

 

----------------

<?PHP
     	 include ('verify.php');
 include ('config.php');
 echo "Check";
 require('global.php'); 
?>

---------------

 

Any idea why? If this code worked when you enter the first time, there must be something throwing it off when you get send back to it after is has completed the task of inserting the user.

 

Link to comment
Share on other sites

pardon me if this is a stupid comment.....did you forget to take out the exit statment directly following that? you posted:

//include ('userr.php');
include ('user.php'); //THIS IS THE TROUBLE INCLUDE FUNCTION!!
//echo "INCLUDE HERE";
exit;
} // END OF NO ERRORS FOUND

 

if you uncomment "include here" does that show up? if you take out the exit; does it continue?

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.