Jump to content

[SOLVED] Passing checkbox information to another php page


jeaker

Recommended Posts

I am having trouble passing a checkbox "samadress" to another page using POST. Here is a little snippit of code.

<td class="whitetext" colspan="2">Billing Info<br />
										  <input type="checkbox" onclick="
if (this.checked) {
document.getElementById('tb').style.display='none';
} else {
document.getElementById('tb').style.display='inline';
}
return true;" name="sameaddress" value="sameaddress" />Check here if billing and shipping info are the same </td>

 

What this basicly does is give a checkbox, and if that box is checked it will make the table underneath it dissapear. That all works fine, my problem is, I cannot get "sameaddress" to pass to my next php page where I want to be able to tell if the box was checked or not. Using the below code.

 

else if($_POST['sameaddress'] == 'on')

LINE 45

 

When I execute my pages I get;

Notice: Undefined index: sameaddress in /www/blah.com/web/www/dev3/newuser2.php on line 45

Line 45 is denoted above. If anyone can tell me what I am doing wrong it would be a great help.

Link to comment
Share on other sites

This is the entire code for the page that has the check box on it.

 

<?php 
include 'unsecure.php';
include 'header.php';

if(isset($_GET['fname']))
{
$fname = $_GET['fname'];
}
else
{
$fname = '';
}
if(isset($_GET['lname']))
{
$lname = $_GET['lname'];
}
else
{
$lname = '';
}
if(isset($_GET['email']))
{
$email = $_GET['email'];
}
else
{
$email = '';
}
if(isset($_GET['address']))
{
$address = $_GET['address'];
}
else
{
$address = '';
}
if(isset($_GET['address2']))
{
$address2 = $_GET['address2'];
}
else
{
$address2 = '';
}
if(isset($_GET['city']))
{
$city = $_GET['city'];
}
else
{
$city = '';
}
if(isset($_GET['state']))
{
$state = $_GET['state'];
}
else
{
$state = '';
}
if(isset($_GET['zip']))
{
$zip = $_GET['zip'];
}
else
{
$zip = '';
}
if(isset($_GET['billaddress']))
{
$billaddress = $_GET['billaddress'];
}
else
{
$billaddress = '';
}
if(isset($_GET['billaddress2']))
{
$billaddress2 = $_GET['billaddress2'];
}
else
{
$billaddress2 = '';
}
if(isset($_GET['billcity']))
{
$billcity = $_GET['billcity'];
}
else
{
$billcity = '';
}
if(isset($_GET['billstate']))
{
$billstate = $_GET['billstate'];
}
else
{
$billstate = '';
}
if(isset($_GET['billzip']))
{
$billzip = $_GET['billzip'];
}
else
{
$billzip = '';
}

?>
<tr>
   <td height="100%" rowspan="2" valign="top">   
      <table border="0" cellpadding="0" cellspacing="0" style="background-color: 0033CC" height="100%" align="center">
         <tr>
            <td width="14"><img src="images/tl_blu.gif" width="14" height="14" border="0"></td>
            <td width="642" colspan="3"></td>
            <td width="14"><img src="images/tr_blu.gif" width="14" height="14" border="0"></td>                        
         </tr>
         <tr>
            <td height="100%"></td>                        
            <td height="100%" colspan="3" align="right" valign="top">
               <table border="0" cellpadding="0" cellspacing="0" style="background-color: FF9900" height="100%">
                  <tr>
                     <td width="14"><img src="images/tl_blkblu.gif" width="14" height="14" border="0"></td>
                     <td style="background-color: 000000" width="627"></td>
                     <td width="14"><img src="images/tr_blkblu.gif" width="14" height="14" border="0"></td>                        
                  </tr>
                  <tr valign="top" height="100%">
                     <td style="background-color: 000000"></td>
                     <td height="100%" style="background-color: 000000" align="center" valign="top"> 
                        <table border="0" bgcolor="white" cellspacing="0" height="100%" width="100%">
                           <tr valign="top">
                              <td bgcolor="black" valign="top">
                              <table width="100%" class="bluetext" cellpadding="5" cellspacing="5" height="100%">
                                 <tr valign="top">
                                   <td width="100%" class="bluetext" height="100%" valign="top">
								<p class="heading">New User Account</p>
								<p class="bluetext">Welcome to the J.A.C.K.S. family. We hope you'll have a great time here and find everything you're looking for. To get started, just fill out the following information. If you already have an account, please log in on the right.</p>
<?php
if(isset($_GET['msg']))
{
$msg = $_GET['msg'];
echo '<p class="redtext">';
switch($msg)
{
	case 1:
		echo "There is already an account registered with this e-mail address. Please log in on the right, or <a class='whitetext' href='retrievepassword.php?email=$email'>click here</a> to retrieve your password.";
		break;
	case 2:
		echo "Please fill in all required fields.";
		break;
	case 3:
		echo "Passwords entered do not match. Please ensure that both password fields are exactly the same.";
		break;
	case 4:
		echo "No accounts match that login info. Please try again on the right, or <a class='whitetext' href='retrievepassword.php?email=$email'>click here to retrieve your password.";
		break;
	case 5:
		echo "If checking the box indicating billing and shipping info are the same, leave billing info blank.";
		break;
}
echo '</p>';
}
?>

								  <form action="newuser2.php" method="post" name="Newuser">
									<table class="bluetext" align="center">
									  <tr>
										<td class="whitetext" colspan="2">Personal Info</td>
									  </tr>
									  <tr>
										<td width="130">First name:</td>
										<td><input type='text' name='fname' id='fname' <?php if(isset($_GET['fname'])) echo "value='$fname'";?> /></td>
									  </tr>
									  <tr>
										<td>Last name:</td>
										<td><input type="text" name="lname" id="lname" <?php if(isset($_GET['lname'])) echo "value='$lname'";?> /></td>
									  </tr>
									  <tr>
										<td>E-mail address:</td>
										<td><input type="text" name="email" id="email" <?php if(isset($_GET['email'])) echo "value='$email'";?> /></td>
									  </tr>
									  <tr>
										<td>Password:</td>
										<td><input type="password" name="password" id="password" /></td>
									  </tr>
									  <tr>
										<td>Verify password:</td>
										<td><input type="password" name="password2" id="password2" /></td>
									  </tr>
									  <tr>
										<td class="whitetext" colspan="2">Shipping Info</td>
									  </tr>
									  <tr>
										<td>Address:</td>
										<td><input type="text" name="address" id="address" <?php if(isset($_GET['address'])) echo "value='$address'";?> /></td>
									  </tr>
									  <tr>
										<td> </td>
										<td><input type="text" name="address2" id="address2" <?php if(isset($_GET['address2'])) echo "value='$address2'";?> /></td>
									  </tr>
									  <tr>
										<td>City:</td>
										<td><input type="text" name="city" id="city" <?php if(isset($_GET['city'])) echo "value='$city'";?> /></td>
									  </tr>
									  <tr>
										<td>State:</td>
										<td><select name="state" id="state">
											<option value=""> </option>
<?php	
$statequery = "SELECT statename, stateabbr FROM state";
$stateresult = mysql_query($statequery);
$statecount = 0;
while($staterow = mysql_fetch_array($stateresult, MYSQL_BOTH))
{
	echo '<option value="' . $staterow['stateabbr'];
	if(isset($_GET['state']))
	{
		if($_GET['state'] == $staterow['stateabbr'])
		{
			echo '" selected = "selected';
		}
	}
	echo '">' . $staterow['statename'] . "</option>";
	$statecount = $statecount + 1;
}
?>											</select> </td>
									  </tr>
									  <tr>
										<td>Zip code:</td>
										<td><input type="text" name="zip" id="zip" <?php if(isset($_GET['zip'])) echo "value='$zip'";?> /></td>
									  </tr>
									  <tr>
										<td class="whitetext" colspan="2">Billing Info<br />
										  <input type="checkbox" onclick="
if (this.checked) {
document.getElementById('tb').style.display='none';
} else {
document.getElementById('tb').style.display='inline';
}
return true;" name="sameaddress" value="sameaddress" />Check here if billing and shipping info are the same </td>
									  </tr>
									  <tr>
									   <td colspan="2">
									   	<table class="bluetext" align="center" id="tb" width="100%">
										 <tr>
										<td width="126">Address:</td>
										<td><input type="text" name="billaddress" id="billaddress" <?php if(isset($_GET['billaddress'])) echo "value='$billaddress'";?> /></td>
									  </tr>
									  <tr>
										<td> </td>
										<td><input type="text" name="billaddress2" id="billaddress2" <?php if(isset($_GET['billaddress2'])) echo "value='$billaddress2'";?> /></td>
									  </tr>
									  <tr>
										<td>City:</td>
										<td><input type="text" name="billcity" id="billcity" <?php if(isset($_GET['billcity'])) echo "value='$billcity'";?> /></td>
									  </tr>
									  <tr>
										<td>State:</td>
										<td><select name="billstate" id="billstate">
											<option value=""> </option>
<?php
$stateresult = mysql_query($statequery);
$statecount = 0;
while($staterow = mysql_fetch_array($stateresult, MYSQL_BOTH))
{
	echo '<option value="' . $staterow['stateabbr'] . '"';
	if($billstate == $staterow['stateabbr'])
	{
		echo '" selected = "selected';
	}
	echo '">' . $staterow['statename'] . "</option>";
	$statecount = $statecount + 1;
}
?>

										</select> </td>
									  </tr>
									  <tr>
										<td>Zip code:</td>
										<td><input type="text" name="billzip" id="billzip" <?php if(isset($_GET['billzip'])) echo "value='$billzip'";?> /></td>
									  </tr></table></td></tr>
									  <tr>
										<td colspan="2" align="center"><input type="Submit" name="Submit" value="Submit" /></td>
									  </tr>
									</table>
								</form>
								</td>
                                 </tr>
                              </table>
                              </td>
                           </tr>
                        </table>
                     </td>
                     <td style="background-color: 000000"></td>
                  </tr>
                  <tr>
                     <td width="14"><img src="images/bl_blkblu.gif" width="14" height="14" border="0"></td>
                     <td style="background-color: 000000" width="627"></td>
                     <td width="14"><img src="images/br_blkblu.gif" width="14" height="14" border="0"></td>
                  </tr>
               </table>
            </td>
            <td height="100%"></td>
         </tr>
         <tr>
            <td width="14"><img src="images/bl_blu.gif" width="14" height="14" border="0"></td>
            <td width="642" colspan="3"></td>
            <td width="14"><img src="images/br_blu.gif" width="14" height="14" border="0"></td>
         </tr>
      </table>
   </td>
   <td valign="top" width="218">
      <?php 
         include 'sidebar.php';
      ?>
   </td>
</tr>

 

And this is the code that the check box is passed to.

<?php 
include 'unsecure.php';
checksession();

$msg = '<br />';
$query = "SELECT UserID, Email FROM User WHERE Email = '" . $_POST['email'] . "'";

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$password = md5($_POST['password']);
$address = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$billaddress = $_POST['billaddress'];
$billaddress2 = $_POST['billaddress2'];
$billcity = $_POST['billcity'];
$billstate = $_POST['billstate'];
$billzip = $_POST['billzip'];

$securitycode = md5($email . $zip);

$msg .= $query . '<br />';

$result = mysql_query($query);
$row = mysql_fetch_array($result);

if($row)
{
header("location:newuser.php?msg=1&fname=$fname&lname=$lname&email=$email&address=$address&address2=$address2&city=$city&state=$state&zip=$zip&billaddress=$billaddress&billaddress2=$billaddress2&billcity=$billcity&billstate=$billstate&billzip=$billzip");
exit();
}
else if($_POST['password'] == '' || $_POST['email'] == '' || $_POST['fname'] == '')
{
header("location:newuser.php?msg=2&fname=$fname&lname=$lname&email=$email&address=$address&address2=$address2&city=$city&state=$state&zip=$zip&billaddress=$billaddress&billaddress2=$billaddress2&billcity=$billcity&billstate=$billstate&billzip=$billzip");
exit();
}
else if($_POST['password'] != $_POST['password2'])
{
header("location:newuser.php?msg=3&fname=$fname&lname=$lname&email=$email&address=$address&address2=$address2&city=$city&state=$state&zip=$zip&billaddress=$billaddress&billaddress2=$billaddress2&billcity=$billcity&billstate=$billstate&billzip=$billzip");
exit();
}
else if($_POST['sameaddress'] == 'on')
{
//Billing address checker activated.
if($billaddress != '' || $billaddress2 != '' || $billcity != '' || $billstate != '' || $billzip != '')
{
	// Billing address fields are filled in, it's illegal.
	if($address != '' || $address2 != '' || $city != '' || $state != '' || $zip != '')
	{
		// They also filled in one of the other fields, this is very illegal.
		header("location:newuser.php?msg=5&fname=$fname&lname=$lname&email=$email&address=$address&address2=$address2&city=$city&state=$state&zip=$zip&billaddress=$billaddress&billaddress2=$billaddress2&billcity=$billcity&billstate=$billstate&billzip=$billzip");
		exit();
	}
}
}

$msg .= 'Success: contact not found. Proceeding.</br >';
$userquery = "INSERT INTO User (FirstName, LastName, Email, Password, securitycode) VALUES ('$fname', '$lname', '$email', '$password', '$securitycode')";
$msg .= $userquery . '<br />';
if(mysql_query($userquery)or die('Error : ' . mysql_error()))
{

	$userid = mysql_insert_id();
	$shipquery = "INSERT INTO Address (userid, address, address2, city, state, zip) VALUES ('$userid', '$address', '$address2', '$city', '$state', '$zip')";
	$msg .= $shipquery . '<br />';
	if(mysql_query($shipquery) or die('Error : ' . mysql_error()))
	{
		$shipid = mysql_insert_id();
		$billquery = "INSERT INTO Address (userid, address, address2, city, state, zip) VALUES ('$userid', '$billaddress', '$billaddress2', '$billcity', '$billstate', '$billzip')";
		$msg .= $billquery . '<br />';
		if(mysql_query($billquery) or die('Error : ' . mysql_error()))
		{
			$billid = mysql_insert_id();
			$userquery2 = "UPDATE User SET shipaddress = '$shipid', billaddress = '$billid' WHERE UserID = '$userid'";
			$msg .= $userquery2 . '<br />';
			if(mysql_query($userquery2) or die('Error : ' . mysql_error()))
			{
				$msg .= 'All operations successful! User added.';
			}
			else
			{
				$msg .= 'Userquery2 failed.<br />';
			}

		}
		else
		{
			$msg .= 'Billing query failed.<br />';
		}
	}
	else
	{
		$msg .= 'Shipping query failed.<br />';
	}
}
else
{
	$msg .= 'Userquery failed.<br />';
}



include 'header.php';

?>
<style type="text/css">
.heading
{
color:#0033CC;
font-family: "Comic Sans MS", sans-serif;
font-size:18px;
font-weight:bold;
text-align:center;
}
.bluetext
{
color:#0033CC;
font-family: "Comic Sans MS", "Arial", sans-serif;
font-size:smaller;
font-weight:bold;
text-align:left;
}
</style>
<tr>
   <td height="100%" rowspan="2" valign="top">   
      <table border="0" cellpadding="0" cellspacing="0" style="background-color: 0033CC" height="100%" align="center">
         <tr>
            <td width="14"><img src="images/tl_blu.gif" width="14" height="14" border="0"></td>
            <td width="642" colspan="3"></td>
            <td width="14"><img src="images/tr_blu.gif" width="14" height="14" border="0"></td>                        
         </tr>
         <tr>
            <td height="100%"></td>                        
            <td height="100%" colspan="3" align="right" valign="top">
               <table border="0" cellpadding="0" cellspacing="0" style="background-color: FF9900" height="100%">
                  <tr>
                     <td width="14"><img src="images/tl_blkblu.gif" width="14" height="14" border="0"></td>
                     <td style="background-color: 000000" width="627"></td>
                     <td width="14"><img src="images/tr_blkblu.gif" width="14" height="14" border="0"></td>                        
                  </tr>
                  <tr valign="top" height="100%">
                     <td style="background-color: 000000"></td>
                     <td height="100%" style="background-color: 000000" align="center" valign="top"> 
                        <table border="0" bgcolor="white" cellspacing="0" height="100%" width="100%">
                           <tr valign="top">
                              <td bgcolor="black" valign="top">
                              <table width="100%" cellpadding="5" cellspacing="5" height="100%">
                                 <tr valign="top">
                                   <td width="100%" class="bluetext" height="100%" valign="top">
								<p class="heading">MY SHOPPING BAG </p>
								Items currently in your shopping bag:
								<?php echo $msg; ?></td>
                                 </tr>
                              </table>
                              </td>
                           </tr>
                        </table>
                     </td>
                     <td style="background-color: 000000"></td>
                  </tr>
                  <tr>
                     <td width="14"><img src="images/bl_blkblu.gif" width="14" height="14" border="0"></td>
                     <td style="background-color: 000000" width="627"></td>
                     <td width="14"><img src="images/br_blkblu.gif" width="14" height="14" border="0"></td>
                  </tr>
               </table>
            </td>
            <td height="100%"></td>
         </tr>
         <tr>
            <td width="14"><img src="images/bl_blu.gif" width="14" height="14" border="0"></td>
            <td width="642" colspan="3"></td>
            <td width="14"><img src="images/br_blu.gif" width="14" height="14" border="0"></td>
         </tr>
      </table>
   </td>
   <td valign="top" width="218">
      <?php 
         include 'sidebar.php';
      ?>
   </td>
</tr>

Link to comment
Share on other sites

try this:

reply

else if($_POST['sameaddress'] == 'on')

to

else if($_POST['sameaddress'] == 'sameaddress')

 

 

I have tryed that. Its still gives me the erroer message

Notice: Undefined index: sameaddress in /www/jacks4comics.com/web/www/dev3/newuser2.php on line 42

 

Everything works like it should it just puts the message on the top of the page.

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.