Jump to content

[SOLVED] Having some trouble with drop down box selection


Haroskyline

Recommended Posts

I'm having some trouble figuring out what is wrong in this code.

It could range from a few programs though.

 

		<?PHP
	if ($_GET['serv'] == 1)
		print "<h1 align=\"center\">Add New Service To a Child</h1>";
	if ($_GET['serv'] == 2)
		print "<h1 align=\"center\">Update Child's Services</h1>";
	?>		
</div>
</div>
<br /><br />

<div align="center">
<form name="myform">
<?PHP
print "<select name=\"sname\" ONCHANGE=\"sendpost()\" style=\"font: 12pt Arial;\">";
print "<option value=\"\">Select the client to modify.</option>";
$results = $db->get_results("SELECT * FROM childdemo ORDER BY Name",OBJECT);
foreach ($results as $key)
{
	print "<option value=".$key->ssn.">".$key->name."</option>";
}
print "</select>";
print "<input type=\"submit\" name=\"go\" value=\"Go\">";
?>

 

There are two pages, called Update Services and Add Services. Update services actually goes to the page it's supposed to based on the student, while Add Services just refreshes the page. Why will only one of them work?

 

Sorry for the delayed reply. Basically, depending on which record is selected (Which child), it should go to an update page, or a page to add services to that specific child. Which, I believe is pre built.

It's difficult to work with someone else's unfinished code. D:

I tried to only upload the part of the code that I thought was effected.

 

Lets see, I'll have another look.

We've got this part from "select_service.php":

<?PHP
	if ($_GET['serv'] == 1)
		print "<h1 align=\"center\">Add New Service To a Child</h1>";
	if ($_GET['serv'] == 2)
		print "<h1 align=\"center\">Update Child's Services</h1>";
	?>		
</div>
</div>
<br /><br />

<div align="center">
<form name="myform">
<?PHP
print "<select name=\"sname\" ONCHANGE=\"sendpost()\" style=\"font: 12pt Arial;\">";
print "<option value=\"\">Select the client to modify.</option>";
$results = $db->get_results("SELECT * FROM childdemo ORDER BY Name",OBJECT);
foreach ($results as $key)
{
	print "<option value=".$key->ssn.">".$key->name."</option>";
}
print "</select>";
print "<input type=\"submit\" name=\"go\" value=\"Go\">";
?>
</form>

I believe this is telling the selection box what to fill up with. What I can't figure out, is why the form submission will work for "serv=2" but not for "serv=1".

 

Then there's this from the "Index.php" that has to do with both pages:

	/*{{{ New Service */
//	if ($_GET['serv'] == 1)
case $_GET['serv'] == 1:
//	{
	if (isset($_POST['save']))
	{
		$query = "INSERT INTO services ( `ssn` , `fhr` , `service` , `vendor` , `begin` , `end` , `days` ";
		$query .= ", `sessions` , `amt` , `funded` , `site` , `schoolyear` , `stac3` ) ";
		$query .= "VALUES ( ".$_POST['ssn'];
		$query .= ", ".$_POST['fhr'];
		$query .= ", ".$_POST['services'];
		$query .= ", ".$_POST['provider'];
		$beg = substr($_POST['begin'],4,4).substr($_POST['begin'],0,4);
		$query .= ", ".$beg;
		$end = substr($_POST['end'],4,4).substr($_POST['end'],0,4);
		$query .= ", ".$end;
		$query .= ", ".$_POST['days'];
		$query .= ", ".$_POST['sessions'];
		$query .= ", ".$_POST['amount'];
		$query .= ", '".$_POST['funded']."'";
		$query .= ", ".$_POST['site'];
		$query .= ", ".$_POST['schoolyear'];
		if (isset($_POST['stac']))
			$query .= ", 1)";
		else
			$query .= ", 0)";

		$ins = mysql_query($query);
		if (!$ins)
			$er->display_error(4); // Duplicate Service error
		else
		{
			print "<br /><br />";
			print "<div style=\"text-align: center; background-color: #FFFFFF; margin: 0px; padding: 0px;	border: 2px solid #CCCCCC; border-spacing: 0px; border-collapse: collapse; width: 70%; margin-left: auto; margin-right: auto;\">";
			print "<div style=\"background-color: #f5f5f5; border: solid 1px #d5d5d5; padding: 1px 1px 1px 1px;	border-collapse: collapse;\">";
			print "<h1 align=\"center\">Enter New Service for a Child</h1>";
			print "</div>";
			print "<br /><br /><h2 align=\"center\">Record successfully added.</h2>";
			print "<br />";
			print "</div>";
		}
	} // if save
	else
	{
		include "include/addserv.inc.php";
	}
//	}
break;
/*}}}*/

/*{{{ Update Services */
//	if ($_GET['serv'] == 2)
case $_GET['serv'] == 2:
//	{
	if (isset($_POST['save']) && (!isset($_POST['service'])))
	{
		$query = "UPDATE services SET ";
		$query .= "ssn=".$_POST['ssn'];
		$query .= ", fhr=".$_POST['fhr'];
		$query .= ", service=".$_POST['services'];
		$query .= ", vendor=".$_POST['provider'];
		$beg = substr($_POST['begin'],4,4).substr($_POST['begin'],0,4);
		$query .= ", begin=".$beg;
		$end = substr($_POST['end'],4,4).substr($_POST['end'],0,4);
		$query .= ", end=".$end;
		$query .= ", days=".$_POST['days'];
		$query .= ", sessions=".$_POST['sessions'];
		$query .= ", amt=".$_POST['amount'];
		$query .= ", funded='".$_POST['funded']."'";
		$query .= ", site=".$_POST['site'];
		$query .= ", schoolyear=".$_POST['schoolyear'];
		if ($_POST['stac'] == "Y")
			$query .= ", stac3=1";
		else
			$query .= ", stac3=0";
		$query .= " WHERE ssn=".$_POST['ssn'];

		$db->query($query);
		$upd = mysql_query($query);
		if (!$upd)
			$er->display_error(5,$query); // Update error
		else
		{
			print "<br /><br />";
			print "<div style=\"text-align: center; background-color: #FFFFFF; margin: 0px; padding: 0px;	border: 2px solid #CCCCCC; border-spacing: 0px; border-collapse: collapse; width: 70%; margin-left: auto; margin-right: auto;\">";
			print "<div style=\"background-color: #f5f5f5; border: solid 1px #d5d5d5; padding: 1px 1px 1px 1px;	border-collapse: collapse;\">";
			print "<h1 align=\"center\">Update Child's Services</h1>";
			print "</div>";
			print "<br /><br /><h2 align=\"center\">Record successfully updated.</h2>";
			print "<br />";
			print "<form name=\"update\" method=\"post\" action=\"index.php?serv=2\"><input type=\"submit\" value=\"New Selection\"></form>";
			print "<br /><br />";
			print "</div>";
		}
	}
	else
	{
		include "include/updateserv.inc.php";
	}

 

This is the included "updateserv.inc.php"

<?PHP
if ((!isset($_POST['sssn'])) or (isset($_POST['newselect'])))
{
	include "include/select_service.php";
	exit();
}		
$oldssn = $_POST['sssn'];
$oldserv = substrpos($_POST['service'], 0, '\-');
$oldid = substr(substrpos($_POST['service'], '\-', 10),1);

$result = $db->get_results("SELECT fname, mname, lname FROM childdemo WHERE ssn = $oldssn",OBJECT);
foreach ($result as $child)
{
	$name = $child->fname;
	$name .= ($child->mname == NULL) ? "" : " ".$child->mname.".";
	$name .= " ".$child->lname;
}
$cnt = $db->get_var("SELECT count(*) FROM services WHERE ssn = $oldssn");

if ($cnt ==0)
	include "include/no_rec_found.inc.php";

if (($cnt > 1) && (!isset($_POST['service'])))
{
?>

And last, this is addserv.inc.php

They're all connected.

<!-- /*{{{*/ PHP section to find selected records -->
<?PHP
if ((!isset($_POST['sname'])) or (isset($_POST['newselect'])))
{
	include "include/select_service.php";
	exit();
}		
$oldssn = $_POST['sname'];

$result = $db->get_results("SELECT fname, mname, lname FROM childdemo WHERE ssn = $oldssn",OBJECT);
foreach ($result as $child)
{
	$name = $child->fname;
	$name .= ($child->mname == NULL) ? "" : " ".$child->mname;
	$name .= ". ".$child->lname;
}

?><!-- /*}}}*/ -->

 

I feel bad for posting so many lines of code.

 

The action wouldn't matter though if there is no submit button.

 

I see on change you have it stated

 

ONCHANGE=\"sendpost()\"

 

What is this function supposed to do?  This is likely where you are erroring out.

I think what it's supposed to do is, when it changes, it's supposed to call for the page to update/add for the person selected.

Oh wow, so

	print "<select name=\"sname\" ONCHANGE=\"sendpost()\" style=\"font: 12pt Arial;\">";

This part right here, on change it runs this javascript:

 

<head>
<title>Select Child's Name to Edit</title>
<script type="text/javascript" language="javascript" >
function sendpost() {
document.forms['myform'].method='post';
document.forms['myform'].action='index.php?serv=<?PHP echo $_GET['serv']; ?>';
document.forms['myform'].target='_self';
document.forms['myform'].submit();
}
</script>
</head>

I got it.

print "<select name=\"sname\" ONCHANGE=\"sendpost()\" style=\"font: 12pt Arial;\">";

This part right here, where it says sname, that only is associated with one of the two files. Add Services, I believe.

While sssn is associated with update services.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.