I'm sure that I'm doing something totally wrong, so don't bash me for that. I don't expect anyone to write a ton of code for me, just help me find the breakdown that is causing my db to change the entire column when I submit a new form. I suspect that my problem lies in the relationships between the following parts of the code, but my inexperience doesn't help me figure out what is actually going wrong. Thanks in advance for your help. Also, I can't get textarea on the form to submit anything, ever. It's just blank. I've tried it a number of ways, thinking maybe I was missing something minor, so take what you see there with a grain of salt.
Code: Select all
mysql_query ("INSERT INTO Agency_Contacts (category, agency_name, primary_contact_name, phone_no, email_web, street, city, state, region, client_pop, hours, services)
VALUES ('$category', '$agency_name', '$primary_contact_name', '$phone_no', '$email_web', '$street', '$city', '$state', '$region', '$client_pop', '$hours', '$services')
");
if ($CATEGORY_ARRAY)
{
$CATEGORY = implode($CATEGORY_ARRAY, ",");
$result = mysql_query ("UPDATE Agency_Contacts
SET CATEGORY = '$CATEGORY'
");
if(!$result)
{
echo "<B>UPDATE unsuccessful:</b> ", mysql_error();
exit;
}
}
DataEntry.html
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="Agency Submission" name="form1" method="GET" action="../../cgi-bin/submitform.php">
Agency Category (check all that apply):
<br />
<label>
<input type="checkbox" name="CATEGORY_ARRAY[]" id="Administrative" value="Administrative" />
Administrative</label>
<label>
<br />
<input type="checkbox" name="CATEGORY_ARRAY[]" id="Advocacy/Social Justice" value="Advocacy/Social Justice" />
Advocacy/Social Justice</label>
<label><br />
<input type="checkbox" name="CATEGORY_ARRAY[]" id="Community Practice" value="Community Practice" />
Community Practice</label>
<p>Agency Name:
<input type=text name="agency_name" size=75 maxlength=75>
</p>
<p>Primary Contact:
<input type=text name="primary_contact_name" size=25 maxlength=25>
</p>
<p>
Contact Phone no.:
<input name=phone_no type=text value="(555)555-1212" size=25 maxlength=25>
</p>
<p>Email/Website:
<input name=email_web type=text value="Separate with a comma" size=25 maxlength=75>
</p>
<p>Street Address:
<input type=text name=street size=25 maxlength=50>
</p>
<p>City:
<input type=text name=city size=25 maxlength=25>
</p>
<p>State:
<input name=state type=text value="XX" size=6 maxlength=2>
</p>
Region of your state in which services are available (check all that apply):
<label>
<br />
<input type="checkbox" name="REGION_ARRAY[]" id="North" value="North" />
North</label>
<label>
<br />
<input type="checkbox" name="REGION_ARRAY[]" id="East" value="East" />
East</label>
<label><br />
<input type="checkbox" name="REGION_ARRAY[]" id="South" value="South" />
South</label>
<label><br />
<input type="checkbox" name="REGION_ARRAY[]" id="West" value="West" />
West</label>
<p>Client populations served (select all that apply): </p>
<label>
<input type="checkbox" name="CLIENT_POP_ARRAY[]" id="Adult-Male" value="Adult-Male" />
Adult-Male</label>
<label>
<br />
<input type="checkbox" name="CLIENT_POP_ARRAY[]" id="Adult-Female" value="Adult-Female" />
Adult-Female</label>
<label>
<br />
<input type="checkbox" name="CLIENT_POP_ARRAY[]" id="Child/School" value="Child/School" />
Child/School</label>
<label><br />
<input type="checkbox" name="CLIENT_POP_ARRAY[]" id="Domestic Violence" value="Domestic Violence" />
Domestic Violence</label>
<p>Services Available: </p>
<p>
<textarea cols=75 rows=5 name="SERVICES_ARRAY" value="">List services separated by a comma</textarea>
</p>
<p>
<input type=submit>
</form>
<p> </p>
</body>
</html>
Code: Select all
<html>
<body>
<p><?php
$link = mysql_connect('host', 'user', 'pass');
mysql_select_db(resources2010);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_query ("INSERT INTO Agency_Contacts (category, agency_name, primary_contact_name, phone_no, email_web, street, city, state, region, client_pop, hours, services)
VALUES ('$category', '$agency_name', '$primary_contact_name', '$phone_no', '$email_web', '$street', '$city', '$state', '$region', '$client_pop', '$hours', '$services')
");
if ($CATEGORY_ARRAY)
{
$CATEGORY = implode($CATEGORY_ARRAY, ",");
$result = mysql_query ("UPDATE Agency_Contacts
SET CATEGORY = '$CATEGORY'
");
if(!$result)
{
echo "<B>UPDATE unsuccessful:</b> ", mysql_error();
exit;
}
}
if ($REGION_ARRAY)
{
$REGION = implode($REGION_ARRAY, ",");
$result = mysql_query ("UPDATE Agency_Contacts
SET REGION = '$REGION'
");
if(!$result)
{
echo "<B>UPDATE unsuccessful:</b> ", mysql_error();
exit;
}
}
if ($CLIENT_POP_ARRAY)
{
$CLIENT_POP = implode($CLIENT_POP_ARRAY, ",");
$result = mysql_query ("UPDATE Agency_Contacts
SET CLIENT_POP = '$CLIENT_POP'
");
if(!$result)
{
echo "<B>UPDATE unsuccessful:</b> ", mysql_error();
exit;
}
}
if ($SERVICES_ARRAY)
{
$SERVICES = implode($SERVICES_ARRAY, ",");
$result = mysql_query ("UPDATE Agency_Contacts
SET SERVICE = '$SERVICES'
");
if(!$result)
{
echo "<B>UPDATE unsuccessful:</b> ", mysql_error();
exit;
}
}
print ("Thanks for submitting your agency information.");
?>
</p>
</body>
</html>