Jump to content

data not inserting into mysql


wikedawsum

Recommended Posts

I'm a bit stumped here, and wondering if someone can tell me what's going on with a registration form I have setup. I'm using radio buttons for people to select which topics apply to them, and the selected radio button value should be inserted into my database. For some reason, not all of my values are being inserted. I am posting my registration form, and the php script that should insert the data into my database.

 

join.php

<?php 
include_once('include_fns.php');
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../css/members.css">
</head>

<body>

<h1>Membership Registration</h1>
<FORM METHOD="POST" ACTION="register.php">
<table border="0" cellpadding="0" cellspacing="5">
<tr>
	<td>First Name:</td>
	<td><input type="text" name="fname" size="25" maxlength="100"></td>
</tr>
<tr>
	<td>Last Name:</td>
	<td><input type="text" name="lname" size="25" maxlength="100"></td>
</tr>
<tr>
	<td>Email:</td>
	<td><input type="text" name="email" size="25" maxlength="200"></td>
</tr>
<tr>
	<td>Address Line 1:</td>
	<td><input type="text" name="address1" size="25" maxlength="100"></td>
</tr>
<tr>
	<td>Address Line 2:</td>
	<td><input type="text" name="address2" size="25" maxlength="100"></td>
</tr>
<tr>
	<td>City:</td>
	<td><input type="text" name="city" size="25" maxlength="100"></td>
</tr>
<tr>
	<td>State:</td>
	<td><input type="text" name="state" size="25" maxlength="10"></td>
</tr>
<tr>
	<td>Postal Code:</td>
	<td><input type="text" name="zip" size="25" maxlength="15"></td>
</tr>
<tr>
	<td>Username:</td>
	<td><input type="text" name="username" size="25" maxlength="100"></td>
</tr>
<tr>
	<td>Password:</td>
	<td><input type="text" name="password" size="25" maxlength="16"></td>
</tr>
<tr>
	<td>Re-enter Your Password:</td>
	<td><input type="text" name="password2" size="25" maxlength="16"></td>
</tr>
</table>
<br />
<div class="hr"><hr /></div>
<table border="0" cellpadding="0" cellspacing="5">
<tr>
	<th><h2>Please send me the following eNewsletters!</h2></th>
</tr>
<tr>
	<td><input type="checkbox" name="newsletter" value="Yes" checked="checked"> Newsletter – Pioneer Interviews, editorial. Sent Monthly.</td>
</tr>
<tr>
	<td><input type="checkbox" name="breakingnews" value="Yes" checked="checked"> Breaking News – Sent when important new occurs.</td>
</tr>
<tr>
	<td><input type="checkbox" name="alerts" value="Yes" checked="checked"> Alerts – Notices about events, media & products.</td>
</tr>
<tr>
	<td><input type="checkbox" name="partners" value="Yes" checked="checked"> Please sent me information from partners who you feel would be of interest to me.</td>
</tr>
</table>
<br />
<div class="hr"><hr /></div>
<table border="0" cellpadding="0" cellspacing="5">
<tr>
	<th><h2>I am interested in these topics:</h2></th> 
</tr>
<tr>
	<th><p class="left">Check all that apply.</p></th>
</tr>
<tr>
	<td><input type="checkbox" name="topics[]" value="Networking"> Networking</td>
</tr>
<tr>
	<td><input type="checkbox" name="topics[]" value="Power Lunches"> Power Lunches</td>
</tr>
<tr>
	<td><input type="checkbox" name="topics[]" value="Entrepreneur Workshop"> Entrepreneur Workshop</td>
</tr>
<tr>
	<td><input type="checkbox" name="topics[]" value="Financial and Retirement Planning"> Financial and Retirement Planning</td>
</tr>
<tr>
	<td><input type="checkbox" name="topics[]" value="Executive Coaching"> Executive Coaching</td>
</tr>
<tr>
	<td><input type="checkbox" name="topics[]" value="Mentoring"> Mentoring Program</td>
</tr>
<tr>
	<td><input type="checkbox" name="topics[]" value="Charity"> Charity Involvement</td>
</tr>
<tr>
	<td><input type="checkbox" name="topics[]" value="Encouragement"> Encouragement</td>
</tr>
<tr>
	<td><input type="checkbox" name="topics[]" value="Career Change/Advice"> Career Change/Advice</td>
</tr>
<tr>
	<td>Other <input type="text" name="topics[]" size="25"></td>
</tr>
</table>
<br />
<div class="hr"><hr /></div>
<table border="0" cellpadding="0" cellspacing="5">
<tr>
	<th><h2>Tell Us About You</h2></th>
</tr>
<tr>
	<td>Company Name: <input type="text" name="company_name" size="25" maxlength="100"></td>
	<td> </td>
</tr>
<tr>
	<th><strong>Industry</strong></th><th><strong>Function</strong></th>
</tr>
<tr>
	<td><input type="radio" name="industry" value="Consumer" checked="checked"> Consumer</td>
	<td><input type="radio" name="function" value="Executive" checked="checked"> Executive</td>
</tr>
<tr>
	<td><input type="radio" name="industry" value="Government/Public Service"> Government/Public Service</td>
	<td><input type="radio" name="function" value="Finance/Accounting"> Finance/Accounting</td>
</tr>
<tr>
	<td><input type="radio" name="industry" value="Health/Bio/Pharmaceutical"> Health/Bio/Pharmaceutical</td>
	<td><input type="radio" name="function" value="Management"> Management</td>
</tr>
<tr>
	<td><input type="radio" name="industry" value="Industrial"> Industrial</td>
	<td><input type="radio" name="function" value="Manufacturing"> Manufacturing</td>
</tr>
<tr>
	<td><input type="radio" name="industry" value="Legal"> Legal</td>
	<td><input type="radio" name="function" value="Marketing"> Marketing</td>
</tr>
<tr>
	<td><input type="radio" name="industry" value="Media/Advertising"> Media/Advertising</td>
	<td><input type="radio" name="function" value="Operations"> Operations</td>
</tr>
<tr>
	<td><input type="radio" name="industry" value="Non-Profit"> Non-Profit</td>
	<td><input type="radio" name="function" value="R&D"> R & D</td>
</tr>
<tr>
	<td><input type="radio" name="industry" value="Services"> Services</td>
	<td><input type="radio" name="function" value="Sales"> Sales</td>
</tr>
<tr>
	<td><input type="radio" name="industry" value="Technical/Telecom"> Technical/Telecom</td>
	<td><input type="radio" name="function" value="Domestic Goods"> Domestic Goods</td>
</tr>
<tr>
	<td>Other: <input type="text" name="industry" size="25" maxlength="100"></td>
	<td>Other: <input type="text" name="function" size="25" maxlength="100"></td>
</tr>
<tr>
	<th><strong>Role</strong></th><th><strong>Age</strong></th>
</tr>
<tr>
	<td><input type="radio" name="role" value="Entry Level" checked="checked"> Entry Level</td>
	<td><input type="radio" name="age" value="< 27" checked="checked"> < 27</td>
</tr>
<tr>
	<td><input type="radio" name="role" value="Manager"> Manager</td>
	<td><input type="radio" name="age" value="27-34"> 27-34</td>
</tr>
<tr>
	<td><input type="radio" name="role" value="Director"> Director</td>
	<td><input type="radio" name="age" value="35-42"> 35-42</td>
</tr>
<tr>
	<td><input type="radio" name="role" value="Executive"> Executive</td>
	<td><Input type="radio" name="age" value="43-50"> 43-50</td>
</tr>
<tr>
	<td><input type="radio" name="role" value="Business Owner"> Business Owner</td>
	<td><input type="radio" name="age" value="51-58"> 51-58</td>
</tr>
<tr>
	<td>Other: <input type="text" name="role" size="25" maxlength="100"></td>
	<td><input type="radio" name="age" value="> 58"> > 58</td>
</tr>
<tr>
	<th><strong>Household Income</strong></th><th><strong>Marital Status</strong></th>
</tr>
<tr>
	<td><input type="radio" name="income" value="< 50,000" checked="checked"> < $50,000</td>
	<td><input type="radio" name="marital_status" value="Single" checked="checked"> Single</td>
</tr>
<tr>
	<td><input type="radio" name="income" value="50,000 - 75,000"> $50,000 - $75,000</td>
	<td><input type="radio" name="marital_status" value="Partnered"> Partnered</td>
</tr>
<tr>
	<td><input type="radio" name="income" value="75,000 - 100,000"> $75,000 - $100,000</td>
	<td><input type="radio" name="marital_status" value="Married"> Married</td>
</tr>
<tr>
	<td><input type="radio" name="income" value="> 100,000"> > $100,000</td>
	<td><input type="radio" name="marital_status" value="Divorced"> Divorced</td>
</tr>
<tr>
	<th><strong>Children in Home?</strong></th><th><strong>If yes, children ages</strong></th>
</tr>
<tr>
	<td><input type="radio" name="children" value="Yes" checked="checked"> Yes</td>
	<td><input type="checkbox" name="children_age[]" value="0-2"> 0-2</td>
</tr>
<tr>
	<td><input type="radio" name="children" value="No"> No</td>
	<td><input type="checkbox" name="children_age[]" value="2-5"> 2-5</td>
</tr>
<tr>
	<td> </td>
	<td><input type="checkbox" name="children_age[]" value="5-11"> 5-11</td>
</tr>
<tr>
	<td> </td>
	<td><input type="checkbox" name="children_age[]" value="11-15"> 11-15</td>
</tr>
<tr>
	<td> </td>
	<td><input type="checkbox" name="children_age[]" value="15-18"> 15-18</td>
</tr>
<tr>
  		<td>Profile Picture</td>
</tr>
<tr>
  		<td><input type="file" name="picture" size="40"></td>
</tr>
<tr>
	<td>In your own words, tell us a little about yourself.</td>
<tr>
<tr>
	<td><textarea name="description" rows="5" cols="30" wrap="virtual"></textarea></td>
<tr>
</table>
<input type="submit" value="Submit">
</FORM>

</body>
</html>

 

register.php

<?php

$conn = mysql_connect("localhost", "******", "******") 
   or die($msg_no_connect);
   mysql_select_db("******") 
   or die(mysql_error());

$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$newsletter  =  (empty($_POST['newsletter']))  ?  0  :  $_POST['newsletter'];
$breakingnews  =  (empty($_POST['breakingnews']))  ?  0  :  $_POST['breakingnews'];
$alerts  =  (empty($_POST['alerts']))  ?  0  :  $_POST['alerts'];
$partners  =  (empty($_POST['partners']))  ?  0  :  $_POST['partners']; 
$topics=$_POST['topics'];
$company=$_POST['company_name'];
$industry=$_POST['industry'];
$function=$_POST['function'];
$role=$_POST['role'];
$age=$_POST['age'];
$income=$_POST['income'];
$marital_status=$_POST['marital_status'];
$children=$_POST['children'];
$children_age=$_POST['children_age'];
$description=$_POST['description'];
$target = 'images/';
$target = $target . basename($_FILES['picture']['name']);
$ok=1;


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>The Pink Compass</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../css/members.css">
</head>

<body>

<h1>Membership Registration</h1>
<?php $sql = "select * from users where username='$username' and password='$password'";
   $res = mysql_query($sql);
   if(mysql_num_rows($res) > 0){
   echo "<p>That username is already taken. Please <a href=\"#\" onclick=\"javascipt:history.go(-1)\">go back</a> and select another one.</p>";
   }

   if ($password != $password2) {
   echo "<p>The passwords you have entered do not match. Please <a href=\"#\" onclick=\"javascipt:history.go(-1)\">try again</a>.</p>";
   }

   if (!eregi("^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
         echo "<p>The e-mail address you submitted does not appear to be valid. Please <a href=\"#\" onclick=\"javascipt:history.go(-1)\">go back</a> and correct it.</p>";
	}

   else if (mysql_num_rows($res) == 0 ) {

   $res2 = mysql_query("insert into users (fname, lname, username, password, email, address1, address2, city, 
   			 state, zip, newsletter, breakingnews, alerts, partners, topics, company_name, industry, function, role, 
   			 age, income, marital_status, children, children_age, description) 
  			     values ('$fname', '$lname', '$username', '$password', '$email', '$address1', '$address2', '$city', 
			 '$state', '$zip', '$newsletter', '$breakingnews', '$alerts', '$partners', '" . implode(',', $_POST['topics']) ."', 
			 '$company', '$industry', '$function', '$role', '$age', '$income', '$marital_status', '$children', 
			 '" . implode(',', $_POST['children_age']) ."', '$description')") or die (mysql_error());

   			    if(!$res2){
     			echo "<p>We're sorry. You could not be registered at this time. Please contact the <a href='mailto:mail@mail.com'>administrator</a> for assistance.<p>";
  				}
			else {
			echo "You have successfully registered. You may now <a href='login.php'>Login</a></p><br />";
			$mailheaders = "From: website.com\n";
			$mailheaders .= "A new user has registered at website.com.\n\n";
			$mailheaders .= "Information about the user:\n";
			$mailheaders .= "Name: $_POST[fname] $_POST[lname]\n";
			$mailheaders .= "Username: $_POST[username]\n";
			$mailheaders .= "Password: $_POST[password]\n";
			$mailheaders .= "E-Mail Address: $_POST[email]\n";
			$mailheaders .= "Address Line 1: $_POST[address1]\n";
			$mailheaders .= "Address Line 2: $_POST[address2]\n";
			$mailheaders .= "City: $_POST[city]\n";
			$mailheaders .= "State: $_POST[state]\n";
			$mailheaders .= "Postal Code: $_POST[zip]\n";
			$mailheaders .= "Company Name: $_POST[company_name]\n";
			$mailheaders .= "Subscribe to: Newsletter - $_POST[newsletter], Breaking News - $_POST[breakingnews], Alerts - $_POST[alerts], Partners - $_POST[partners]\n";
			$mailheaders .= "Topics: " . implode(',', $_POST['topics']) ."\n";
			$mailheaders .= "Industry: $_POST[industry]\n";
			$mailheaders .= "Function: $_POST[function]\n";
			$mailheaders .= "Role: $_POST[role]\n";
			$mailheaders .= "Age: $_POST[age]\n";
			$mailheaders .= "Income: $_POST[income]\n";
			$mailheaders .= "Marital Status: $_POST[marital_status]\n";
			$mailheaders .= "Children in Home: $_POST[children]\n";
			$mailheaders .= "Age of Children: " . implode(',', $_POST['children_age']) ."\n";		

			$to = "mail@mail.com";
			$subject = "New Registration Alert";

			mail($to, $subject, $mailheaders, "From: mail@mail.com\n");
			}
		}
  		 ?>


</body>
</html>

 

At the moment, the only radio button values that are being inserted are age, household income, marital status, and children in home.

 

I am also having issues with people being able to upload an image upon registration. Inside my member's area, I have a place where they can change their profile picture. This script works perfectly. They are able to either add an initial image, or change one that is already in place. However, on their initial registration, the image is not being inserted. That may be another issue entirely so I can provide any code that is needed if someone wants to take a look at that as well.

 

Any input or direction is greatly appreciated. I'm not quite sure why some radio buttons would work, and some wouldn't. Thanks to all who reply!

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.