Hi All,

For some reason, I cannot get the values to pass to the ACTION page correctly in the code below:

<? 
$id_Event = '1';
?>

<head>
</head>

<body>

<form id="form2" name="Operation" method="post" action="EvVolProcess.php?id_Service=<?php echo '$id_Event'; ?>">
<input name="id_Event" type="hidden" id="id_Event" value="<?php echo '$id_Event'; ?>" />
<select name="SelVol" id="SelVol">
<?
	$query = "select id,First_Name,Last_Name from Volunteers order by Last_Name,First_Name";
	$result = mysql_query ($query) or die ("select failed : ".mysql_error());
    while($line = mysql_fetch_array($result))
	{
        echo "<option value = \"".$line[0]."\">".$line[2].", ".$line[1]."</option>\n";
    } 
?>
</select>

&nbsp; <input name="Operation" type="submit" id="Operation" value="ADD" />
&nbsp; <input name="Operation" type="submit" id="Operation" value="Email" />
</form>

</body>

ACTION page looks like this:

<?
$id_Vol = $_POST['SelVol'];
$id_Service = $_POST['id_Service'];
//print_r($_POST['ADD']);
//print_r($id_Vol);
//print_r($id_Service);
?>


<?php
	require_once('auth.php');
?>

<? 
include("inc/interface.php");
include("inc/funct.php");
ServerConnect();
DB_Connect();
?> 

<?php

if ($_POST['ADD'])
{

<?php

// Finds the Volunteer to grab more values
$query = "select id,First_Name,Last_Name,Instrumnets from Volunteers where id='$id_Vol'";
$results = mysql_query($query) or die("Error performing query");

// Sets additional values for the the next Query
$Name = .$line[2].", ".$line[1].; // The fields need to format the Name Last_Name, First_Name - HELP!
$Instruments = echo $row['Instruments'];

// Adds new record
$sql="INSERT INTO Ev_AvVolunteers (id_Event, id_Volunteer, Name, Instruments) VALUES ('$id_Event','$id_Vol','$Name','$Instruments')";
//print_r($sql);
$result = mysql_query($sql) or die(mysql_error());

header("location: [Service_Dates_detail.php]"); } else if ($_POST['Email']) {


header("location: [Service_Dates1_detail.php]"); }

?>

I need the $Name to be formatted correctly, SEARCH and ADD actions to work, then to redirect back to the page. Also, I don't think the IF Statement is working correctly. Sigh...

Thanks!

Recommended Answers

All 7 Replies

Don't surround the variable with ' quotes.

Don't surround the variable with ' quotes.

Is that in my HTML page or ACTION page?

Will you include what needs changing please? Thanks!

This:

<?php echo '$id_Event'; ?>

should be:

<?php echo $id_Event; ?>

Also, it is pointless to pass that parameter via _GET and _POST. Choose one. You already have _POST setup so just change:

<form id="form2" name="Operation" method="post" action="EvVolProcess.php?id_Service=<?php echo '$id_Event'; ?>">

to:

<form id="form2" name="Operation" method="post" action="EvVolProcess.php">
<form id="form2" name="Operation" method="post" action="EvVolProcess.php?id_Service=<?php echo '$id_Event'; ?>">

should be

<form id="form2" name="Operation" method="post" action="EvVolProcess.php?id_Service=<?php echo $id_Event; ?>">

edit:: Sorry KKeith, you're already there

$query = "select id,First_Name,Last_Name,Instrument from Volunteers where id=$id_Vol";
print_r($query);
$results = mysql_query($query) or die("Error performing query");
print_r($results);
$Name = .$line[2].", ".$line[1].; // The fields need to format the Name Last_Name, First_Name - HELP!
$Instrument = <?php echo $row['Instrument'];
print_r($Name);
print_r($Instrument);

Why am I not able to set the $Name and $Instrument variables. If i comment the last 4 lines my $Result returns:

371select id,First_Name,Last_Name,Instrument from Volunteers where id=37Resource id #6

Huh?

OK - I am getting farther. My second query is adding the record with the IDS populated correctly. The only problem in the first query. I need to find the one volunteer's record and:

1) store the name in the $Name variable in this format (Last_Name, First_Name)

2) store the Instrument value in the $Instruments variable

The code is below but I have commented ou the the REDIRECT and ADD to see the results of my variables for testing.

Thanks for the help so far...

<?
$id_Vol = $_POST['SelVol'];
$id_Event = $_POST['id_Event'];
$Action = $_POST['Operation'];
print_r($_POST['Operation']);
print_r($id_Vol);
print_r($id_Event);

	require_once('auth.php');
	include("inc/interface.php");
	include("inc/funct.php");
	ServerConnect();
	DB_Connect();

if ($Action == 'ADD')
{

$query = "select id,First_Name,Last_Name,Instrument from Volunteers where id=$id_Vol";
print_r($query);
$result = mysql_query ($query) or die ("select failed : ".mysql_error());
print_r($result);

while ($row = mysql_fetch_array ($results)){ 
$Instrument = $row['Instrument'];
$First_Name = $row['First_Name'];
$Last_Name = $row['Last_Name'];
}

//$Name = .$line[2].", ".$line[1].;

print_r($Instrument);
print_r($First_Name);
print_r($Last_Name);

//$sql="INSERT INTO Ev_AvVolunteers (id_Event, id_Volunteer, Name, Instruments) VALUES ('$id_Event','$id_Vol','$Name','$Instruments')";
//$result = mysql_query($sql) or die(mysql_error());

//header("location: Service_Dates_detail.php");

} else if ($Action == 'Email') {

header("location: [Service_Dates1_detail.php]"); }

?>

I was able to fiddle with and find the combo. Here it is:

<?
$id_Vol = $_POST['SelVol'];
$id_Event = $_POST['id_Event'];
$Action = $_POST['Operation'];
print_r($_POST['Operation']);
print_r($id_Vol);
print_r($id_Event);

	require_once('auth.php');
	include("inc/interface.php");
	include("inc/funct.php");
	ServerConnect();
	DB_Connect();

if ($Action == 'ADD')
{

$query = "select id,First_Name,Last_Name,Instrument from Volunteers where id=$id_Vol";
//print_r($query);
$result = mysql_query ($query) or die ("select failed : ".mysql_error());
//print_r($result);

while ($row = mysql_fetch_array ($result)){ 
$Instrument = $row['Instrument'];
$First_Name = $row['First_Name'];
$Last_Name = $row['Last_Name'];
$Name = "$Last_Name, $First_Name";

}
//print_r($Instrument);
//print_r($First_Name);
//print_r($Last_Name);
//print_r($Name);

$sql="INSERT INTO Ev_AvVolunteers (id_Event, id_Volunteer, Name, Instruments) VALUES ('$id_Event','$id_Vol','$Name','$Instrument')";
//print_r($sql);
$result = mysql_query($sql) or die(mysql_error());
//print_r($result);
header("location: Service_Dates_detail.php");

} else if ($Action == 'Email') {

header("location: [Service_Dates1_detail.php]"); }

?>

Thanks!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.