We help IT Professionals succeed at work.

Create Profile Script

andrewaiello
andrewaiello asked
on
194 Views
Last Modified: 2010-04-16
Hi,

I am creating a form where a user can enter their profile info.  Once entered the info is put into a db and they can later login using their username and password.  Below is the code i have so far and now i am stuck...

I get the following errors when the code is executed:


Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /usr/www/users/profile_new.php:4) in /usr/www/profile_new.php on line 95

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /usr/wwwu/sers/profile_new.php:4) in /usr/www/profile_new.php on line 95

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/profile_new.php:4) in /usr/www/users/profile_new.php on line 133


This is the first time i have used Session variables and im not sure what the problem is...



<html>
<!-- profile_new.php - the form page for creatign a new profile -->
<head><title>Welcome</title></head>
<?php

$host = "xxxx";
$user = "xxxx";
$password ="xxxx";
$db_name = "xxxx";

// initializing a blank error message
// this will be used to accumulate the input errors
// in order to feed them back to the user
$error_message = "";
// checking to make sure the form has actually been submitted
if ($submit_new_profile != "")
{
// if it has been submitted
// each of the form entries will be examined
// to see which have been omitted
if ($_REQUEST['txt_email'] == "")
{

$error_message = "$error_message<br>You have omitted your email address.";

}
else
{


$link = mysql_connect($host, $user, $password) or die (mysql_error());
Mysql_select_db("dmotion_handles") or die(mysql_error());

$query_string = "SELECT * FROM profile WHERE (email = '$txt_email')";

$result_set = mysql_db_query($db_name, $query_string, $link);

while ($row = mysql_fetch_array($result_set))
{

$error_message = "$error_message<br><br>This email address is already in use.<br>";

}

mysql_close($link);

}
if ($_REQUEST['txt_password'] == "")
{

$error_message = "$error_message<br>You have omitted your password.";

}
if ($_REQUEST['txt_bill_first_name'] == "")
{

$error_message = "$error_message<br>You have omitted your first name.";

}
if ($_REQUEST['txt_bill_last_name'] == "")
{

$error_message = "$error_message<br>You have omitted your last name.";

}

if ($_REQUEST['txt_member_number'] == "")
{

$error_message = "$error_message<br>You have omitted the your member number.";


}

if ($error_message != "")
{

echo ("<br><center><font color=ff0000 size=4> $error_message </font></center>");

}

else
{


// user session
session_start();
$_SESSION["active_profile"] = "active";
$_SESSION["email_original"] = $txt_email;
$_SESSION["password_original"] = $txt_password;
$_SESSION["bill_first_name"] = $txt_bill_first_name;
$_SESSION["bill_last_name"] = $txt_bill_last_name;
$_SESSION["member_number"] = $txt_member_number;
$_SESSION["bill_address"] = $txt_bill_address;
$_SESSION["bill_city"] = $txt_bill_city;
$_SESSION["bill_state"] = $sel_bill_state;
$_SESSION["bill_zip"] = $txt_bill_zip;
$_SESSION["bill_phone"] = $txt_bill_phone;
$_SESSION["bill_company"] = $txt_company;


$link = mysql_connect($host, $user, $password) or die (mysql_error());
Mysql_select_db("xxxx") or die(mysql_error());

// query string
$query_string = "INSERT INTO profile
VALUES ('0',
'$txt_email',
'$txt_password',
'$txt_bill_first_name',
'$txt_bill_last_name',
'$txt_member_number',
'$txt_bill_address',
'$txt_bill_city',
'$sel_bill_state',
'$txt_bill_zip',
'$txt_bill_phone',
'$txt_company',

Now( ))";

// executing the SQL statement
mysql_db_query($db_name, $query_string, $link);

mysql_close($link);
header("location:profile_added.php");

}

}
?>
<br><br>
<div align="center">
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
 

<table border="0" cellpadding="6" cellspacing="0" width="600" id="table1">
<tr>
<td colspan = 2 align=center><b><font size="4">*</font> denotes a required entry</b></td>
</tr>
<tr>
<td width="576" align="right">&nbsp;</td>
<td width="576">&nbsp;</td>
</tr>

<tr>
<td width="576" align="right"><font size="2">*First Name:</font></td>
<td width="576">
  <font size="2" face="Arial, Helvetica, sans-serif">
  <input name="txt_bill_first_name" size="15" value = "<?php if (isset($_REQUEST['txt_bill_first_name'])) echo $_REQUEST['txt_bill_first_name']; ?>">
  </font></td>
</tr>
<tr>
  <td align="right"><font size="2">*Last Name:</font></td>
  <td><font size="2" face="Arial, Helvetica, sans-serif">
    <input name="txt_bill_last_name" size="20" value = "<?php if (isset($_REQUEST['txt_bill_last_name'])) echo $_REQUEST['txt_bill_last_name']; ?>">
  </font></td>
</tr>
<tr>
  <td align="right"><font size="2">*Member Number :</font></td>
  <td><font size="2" face="Arial, Helvetica, sans-serif">
    <input name="txt_member_number" size="12" value = "<?php if (isset($txt_member_number)) echo $txt_member_number; ?>">
  </font></td>
</tr>
<tr>
  <td align="right"><font size="2">Phone Number:</font></td>
  <td><font size="2" face="Arial, Helvetica, sans-serif">
    <input name="txt_bill_phone" size="12" value = "<?php if (isset($txt_bill_phone)) echo $txt_bill_phone; ?>">
  </font></td>
</tr>
<tr>
<td width="576" align="right"><font size="2"> Address:</font></td>
<td width="576">
  <font size="2" face="Arial, Helvetica, sans-serif">
  <input name="txt_bill_address" size="40" value = "<?php if (isset($_REQUEST['txt_bill_address'])) echo $_REQUEST['txt_bill_address']; ?>">
  </font></td>
</tr>
<tr>
<td width="576" align="right"><font size="2">City:</font></td>
<td width="576">
  <font size="2" face="Arial, Helvetica, sans-serif">
  <input name="txt_bill_city" size="20" value = "<?php if (isset($_REQUEST['txt_bill_city'])) echo $_REQUEST['txt_bill_city']; ?>">
  </font></td>
</tr>
<tr>
<td width="576" align="right"><font size="2">State:</font></td>
<td width="576">
  <font size="2" face="Arial, Helvetica, sans-serif">
  <select size="1" name="sel_bill_state">
    <option value = "no_select" <?php if (($_REQUEST['sel_bill_state']) == 'no_select') echo 'selected'; ?>>Please Select</option>
    <option value = "Alabama" <?php if (($_REQUEST['sel_bill_state']) == 'Alabama') echo 'selected'; ?>>Alabama</option>
    <option value = "Alaska" <?php if (($_REQUEST['sel_bill_state']) == 'Alaska') echo 'selected'; ?>>Alaska</option>
    <option value = "Arizona" <?php if (($_REQUEST['sel_bill_state']) == 'Arizona') echo 'selected'; ?>>Arizona</option>
    <option value = "Arkansas" <?php if (($_REQUEST['sel_bill_state']) == 'Arkansas') echo 'selected'; ?>>Arkansas</option>
    <option value = "California" <?php if (($_REQUEST['sel_bill_state']) == 'California') echo 'selected'; ?>>California</option>
    <option value = "Colorado" <?php if (($_REQUEST['sel_bill_state']) == 'Colorado') echo 'selected'; ?>>Colorado</option>
    <option value = "Connecticut" <?php if (($_REQUEST['sel_bill_state']) == 'Connecticut') echo 'selected'; ?>>Connecticut</option>
    <option value = "Delaware" <?php if (($_REQUEST['sel_bill_state']) == 'Delaware') echo 'selected'; ?>>Delaware</option>
    <option value = "Florida" <?php if (($_REQUEST['sel_bill_state']) == 'Florida') echo 'selected'; ?>>Florida</option>
    <option value = "Georgia" <?php if (($_REQUEST['sel_bill_state']) == 'Georgia') echo 'selected'; ?>>Georgia</option>
    <option value = "Hawaii" <?php if (($_REQUEST['sel_bill_state']) == 'Hawaii') echo 'selected'; ?>>Hawaii</option>
    <option value = "Idaho" <?php if (($_REQUEST['sel_bill_state']) == 'Idaho') echo 'selected'; ?>>Idaho</option>
    <option value = "Illinois" <?php if (($_REQUEST['sel_bill_state']) == 'Illinois') echo 'selected'; ?>>Illinois</option>
    <option value = "Indiana" <?php if (($_REQUEST['sel_bill_state']) == 'Indiana') echo 'selected'; ?>>Indiana</option>
    <option value = "Iowa" <?php if (($_REQUEST['sel_bill_state']) == 'Iowa') echo 'selected'; ?>>Iowa</option>
    <option value = "Kansas" <?php if (($_REQUEST['sel_bill_state']) == 'Kansas') echo 'selected'; ?>>Kansas</option>
    <option value = "Kentucky" <?php if (($_REQUEST['sel_bill_state']) == 'Kentucky') echo 'selected'; ?>>Kentucky</option>
    <option value = "Louisiana" <?php if (($_REQUEST['sel_bill_state']) == 'Louisiana') echo 'selected'; ?>>Lousiiana</option>
    <option value = "Maine" <?php if (($_REQUEST['sel_bill_state']) == 'Maine') echo 'selected'; ?>>Maine</option>
    <option value = "Maryland" <?php if (($_REQUEST['sel_bill_state']) == 'Maryland') echo 'selected'; ?>>Maryland</option>
    <option value = "Massachusetts" <?php if (($_REQUEST['sel_bill_state']) == 'Massachusetts') echo 'selected'; ?>>Massachusetts</option>
    <option value = "Michigan" <?php if (($_REQUEST['sel_bill_state']) == 'Michigan') echo 'selected'; ?>>Michigan</option>
    <option value = "Minnesota" <?php if (($_REQUEST['sel_bill_state']) == 'Minnesota') echo 'selected'; ?>>Minnesota</option>
    <option value = "Mississippi" <?php if (($_REQUEST['sel_bill_state']) == 'Mississippi') echo 'selected'; ?>>Mississippi</option>
    <option value = "Missouri" <?php if (($_REQUEST['sel_bill_state']) == 'Missouri') echo 'selected'; ?>>Missouri</option>
    <option value = "Montana" <?php if (($_REQUEST['sel_bill_state']) == 'Montana') echo 'selected'; ?>>Montana</option>
    <option value = "Nebraska" <?php if (($_REQUEST['sel_bill_state']) == 'Nebraska') echo 'selected'; ?>>Nebraska</option>
    <option value = "Nevada" <?php if (($_REQUEST['sel_bill_state']) == 'Nevada') echo 'selected'; ?>>Nevada</option>
    <option value = "NewHampshire" <?php if (($_REQUEST['sel_bill_state']) == 'NewHampshire') echo 'selected'; ?>>New Hampshire</option>
    <option value = "NewJersey" <?php if (($_REQUEST['sel_bill_state']) == 'NewJersey') echo 'selected'; ?>>New Jersey</option>
    <option value = "NewMexico" <?php if (($_REQUEST['sel_bill_state']) == 'NewMexico') echo 'selected'; ?>>New Mexico</option>
    <option value = "NewYork" <?php if (($_REQUEST['sel_bill_state']) == 'NewYork') echo 'selected'; ?>>New York</option>
    <option value = "NorthCarolina" <?php if (($_REQUEST['sel_bill_state']) == 'NorthCarolina') echo 'selected'; ?>>North Carolina</option>
    <option value = "NorthDakota" <?php if (($_REQUEST['sel_bill_state']) == 'NorthDakota') echo 'selected'; ?>>North Dakota</option>
    <option value = "Ohio" <?php if (($_REQUEST['sel_bill_state']) == 'Ohio') echo 'selected'; ?>>Ohio</option>
    <option value = "Oklahoma" <?php if (($_REQUEST['sel_bill_state']) == 'Oklahoma') echo 'selected'; ?>>Oklahoma</option>
    <option value = "Oregon" <?php if (($_REQUEST['sel_bill_state']) == 'Oregon') echo 'selected'; ?>>Oregon</option>
    <option value = "Pennsylvania" <?php if (($_REQUEST['sel_bill_state']) == 'Pennsylvania') echo 'selected'; ?>>Pennsylvania</option>
    <option value = "RhodeIsland" <?php if (($_REQUEST['sel_bill_state']) == 'RhodeIsland') echo 'selected'; ?>>Rhode Island</option>
    <option value = "SouthCarolina" <?php if (($_REQUEST['sel_bill_state']) == 'SouthCarolina') echo 'selected'; ?>>South Carolina</option>
    <option value = "SouthDakota" <?php if (($_REQUEST['sel_bill_state']) == 'SouthDakota') echo 'selected'; ?>>South Dakota</option>
    <option value = "Tennessee" <?php if (($_REQUEST['sel_bill_state']) == 'Tennessee') echo 'selected'; ?>>Tennessee</option>
    <option value = "Texas" <?php if (($_REQUEST['sel_bill_state']) == 'Texas') echo 'selected'; ?>>Texas</option>
    <option value = "Utah" <?php if (($_REQUEST['sel_bill_state']) == 'Utah') echo 'selected'; ?>>Utah</option>
    <option value = "Vermont" <?php if (($_REQUEST['sel_bill_state']) == 'Vermont') echo 'selected'; ?>>Vermont</option>
    <option value = "Virginia" <?php if (($_REQUEST['sel_bill_state']) == 'Virginia') echo 'selected'; ?>>Virginia</option>
    <option value = "Washington" <?php if (($_REQUEST['sel_bill_state']) == 'Washington') echo 'selected'; ?>>Washington</option>
    <option value = "WestVirginia" <?php if (($_REQUEST['sel_bill_state']) == 'WestVirginia') echo 'selected'; ?>>West Virginia</option>
    <option value = "Wisconsin" <?php if (($_REQUEST['sel_bill_state']) == 'Wisconsin') echo 'selected'; ?>>Wisconsin</option>
    <option value = "Wyoming" <?php if (($_REQUEST['sel_bill_state']) == 'Wyoming') echo 'selected'; ?>>Wyoming</option>
  </select>
  </font></td>
</tr>
<tr>
<td width="576" align="right"><font size="2">Zip:</font></td>
<td width="576">
  <font size="2" face="Arial, Helvetica, sans-serif">
  <input name="txt_bill_zip" size="10" value = "<?php if (isset($_REQUEST['txt_bill_zip'])) echo $_REQUEST['txt_bill_zip']; ?>">
  </font></td>
</tr>
<tr>
<td width="576" align="right"><font size="2">Company:</font></td>
<td width="576">
  <font size="2" face="Arial, Helvetica, sans-serif">
  <input name="txt_company" id="txt_company" value = "<?php if (isset($txt_company)) echo $txt_company; ?>" size="12">
  </font></td>
</tr>
<tr>
  <td align="right"><font size="2">*E-Mail Address:</font></td>
  <td><font size="2" face="Arial, Helvetica, sans-serif">
    <input type="text" name="txt_email" size="30" value = "<?php if (isset($_REQUEST['txt_email'])) echo $_REQUEST['txt_email']; ?>">
  </font></td>
</tr>
<tr>
  <td align="right"><font size="2">*Create Password:</font></td>
  <td><font size="2" face="Arial, Helvetica, sans-serif">
    <input type="password" name="txt_password" size="12" value = "<?php if (isset($_REQUEST['txt_password'])) echo $_REQUEST['txt_password']; ?>">
  </font></td>
</tr>

<tr>
<td width="576" align="right">&nbsp;</td>
<td width="576">&nbsp;</td>
</tr>
<tr>
<td width="576" align="center" colspan="2">
<input type="submit" value="Submit" name="submit_new_profile" style="font-size: 14pt; font-weight: bold"></td>
</tr>
</table>
<p>&nbsp;</p>
</form>
</div>
</body>
</html>
Comment
Watch Question

HonorGodSoftware Engineer
CERTIFIED EXPERT

Commented:
 I'm sorry, but I don't know PHP.

  From the code, I can't determine how much information you are trying to store in the cookie.

  Could the problem be related to too much information being stored in the cookie?

 Have you considered storing the information in your server database, and only saving a minimal amount of information on the client side?

  You state "I get the following errors when the code is executed"  Is this true the very first time you execute the code? Or only after information is saved in a cookie?

  You might want to search google for +javascript +cookies.

Good luck

Author

Commented:
I just deleted the html tags and it works now...
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.