0

I have a dynamic drop down that allows me to select an item. That item is posted to a new page that I run a query against to build/populate my form that I'm wanting to update a column in. However the issue is after I hit my submit button it no longer knows about my post variable. I get the following error.

on line 39: Undefined index: mevent

Code from drop down. This is in its own php file.

echo "<a href=''>Manage Individual Event Result</a></br>";
$quer2=mysql_query("SELECT DISTINCT event FROM er1 order by event");
// End of query for first list box

echo "<form method=post name=f2 action='mansignleeventr.php'>";
// Add your form processing page address to action in above line. Example  action=dd-check.php
//Starting of first drop downlist 
echo "<select name='mevent' onchange=\"reload(this.form)\"><option value=''>Select Event</option>";
while($noticia2 = mysql_fetch_array($quer2)) { 
if($noticia2['event']==@$cat){echo "<option selected value='$noticia2[event]'>$noticia2[event]</option>"."<BR>";}
else{echo  "<option value='$noticia2[event]'>$noticia2[event]</option>";}
}
echo "</select><input type=submit value=Submit></br>";
echo "</form>";

This is on the mansignleeventr.php page where mevent is passed to. It works on the first population but after I hit submit to update my form I get the error.

<?php
$e=$_POST['mevent']; //gives event now
//echo $e;

$query = "SELECT a.id, a.firstname, a.lastname, e.eorder, e.event, e1.result, e1.eventrank, e1.eventscore, e1.date, e1.id
			FROM
			er1 e1
			LEFT JOIN athlete a ON (e1.athlete_id = a.id)
			LEFT JOIN events e ON (e1.event = e.event)
			where e.event='$e'
			ORDER BY eventrank";
	
$res = mysql_query($query);
	if (!$res){
		die('Error with query: ' . mysql_error());
	}
$k = 1;
$bg = '#eeeeee'; 
while ($row = sqlFetchArray($res)) {
	$id[]=$row['id']; 
	//echo $row['event'];
	$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
	  echo '<tr bgcolor="' . $bg . '">
      <td align="left">' . $row['firstname'] . '</td>
      <td align="left">' . $row['lastname'] . '</td>
      <td align="left"><input name="event[]" id="event" value="' . $row['event'] . '" /></td>
      <td align="left"><input type="text" size="10" name="result[]" id="result" value="'.$row['result'].'" /></td>
      <td align="left">' . $row['eventrank']. '</td>
      <td align="left">' . $row['eventscore']. '</td>
      <td align="left">' . $row['date'] . '</td>
      
      </tr>';
	
	$k++;
	
	
} // End of WHILE loop.
echo '</table>';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';


if(isset($_POST['Submit'])){//1
for($i=0;$i<$count;$i++){//2
	$r = $_POST['result'][$i];

	$e = $_POST['event'][$i];

	$sql = "UPDATE er1 set result='$r' WHERE event='$e' and id='$id[$i]'";	
	mysql_query($sql);
	$res = mysql_query($sql);
	if (!$res){//3
		die('Error with query: ' . mysql_error());
	}//3 
	
	
 //}
 }//2
}//1
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by debow
0

where is starting of form tag in your last code?
and where is $count in line no. 28?
Post complete page and also error you are getting....

0

The files are attached.

display.functions.inc.php has the code for the dynamic select that sends the post data to
mansignleeventr.php. On the initial select the form is populated but after I modify results for any of the events and hit submit I get the error on Undefined index 'mevent'. The rest of the code works, if I hard code the event value it gets updated. Just doesn't work unless its hard-coded.

Attachments
<?php
#### Display Functions ####


function show_userbox()
{
    // retrieve the session information
    $u = $_SESSION['username'];
    $uid = $_SESSION['loginid'];
    
		echo "<br /><h4>Administrator Links</h4>";
		echo "<a href='add_athlete.php' title='Add Athlete'>Add Athletes</a><br />";
		echo  "<a href='viewathlete.php' title='View Athletes'>View Athletes</a><br />";
		echo    "<a href='manageathlete.php' title='Manage Athletes'>Manage Athletes</a><br /><br/>";
		      
		echo "<a href='mevents.php' title='Manage Events'>Manage Events</a><br />";
		echo "<a href='mathleteresults.php' title='Manage Athlete Results'>Manage All Results</a><br />";
		
		echo "<a href=''>Manage Individual Athlete Result</a></br>";
		$quer1=mysql_query("SELECT DISTINCT name,athlete_id FROM er1 order by name");
		// End of query for first list box

		echo "<form method=post name=f1 action='mansignleathleter.php'>";
		// Add your form processing page address to action in above line. Example  action=dd-check.php
		//Starting of first drop downlist 
		echo "<select name='athlete_id' onchange=\"reload(this.form)\"><option value=''>Select Athlete</option>";
		while($noticia1 = mysql_fetch_array($quer1)) { 
		if($noticia1['athlete_id']==@$cat){echo "<option selected value='$noticia1[athlete_id]'>$noticia1[name]</option>"."<BR>";}
		else{echo  "<option value='$noticia1[athlete_id]'>$noticia1[name]</option>";}
		}
		echo "</select><input type=submit value=Submit></br>";
		echo "</form>";
		
		
		
		echo "<a href=''>Manage Individual Event Result</a></br>";
		$quer2=mysql_query("SELECT DISTINCT event FROM er1 order by event");
		// End of query for first list box

		echo "<form method=post name=f2 action='mansignleeventr.php'>";
		// Add your form processing page address to action in above line. Example  action=dd-check.php
		//Starting of first drop downlist 
		echo "<select name='mevent' onchange=\"reload(this.form)\"><option value=''>Select Event</option>";
		while($noticia2 = mysql_fetch_array($quer2)) { 
		if($noticia2['event']==@$cat){echo "<option selected value='$noticia2[event]'>$noticia2[event]</option>"."<BR>";}
		else{echo  "<option value='$noticia2[event]'>$noticia2[event]</option>";}
		}
		echo "</select><input type=submit value=Submit></br>";
		echo "</form>";
		
		
		echo "<br/>";
		echo "<a href='viewallresults.php' title='View All Results'>View All Results</a><br />";
		echo "<a href='' title='View Event Results'>View Event Results</a><br />";
		echo "<a href='' title='View Athlete Results'>View Athlete Results</a><br />";
		echo "<a href='ranktest.php' title='View Athlete Results'>RankTest</a><br />";
		echo "<a href='ranktestbutton.php' title='View Athlete Results'>RankTest2</a><br />";
    
    // display the user box
    echo "<div id='userbox'>
			
			<ul>
				<li><a href='./changepassword.php'>Change Password</a></li>
				<li><a href='./logout.php'>Logout</a></li>
			</ul>
		 </div>";
}

function show_loginform($disabled = false)
{
	echo "<br/><h4>Guest Links</h4>";
	echo "<a href='index.php'>Home</a></br>";
	echo "<a href='viewathlete.php'>View Athletes</a></br>";
	echo "<a href='viewallresults.php'>View All Results</a></br>";
	
  
	echo "<a href=''>View Individual Athlete Result</a></br>";
		$quer1=mysql_query("SELECT DISTINCT name,athlete_id FROM er1 order by name");
		// End of query for first list box

		echo "<form method=post name=f1 action='viewsingleathlete.php'>";
		// Add your form processing page address to action in above line. Example  action=dd-check.php
		//Starting of first drop downlist 
		echo "<select name='athlete' onchange=\"reload(this.form)\"><option value=''>Select Athlete</option>";
		while($noticia1 = mysql_fetch_array($quer1)) { 
		if($noticia1['athlete_id']==@$cat){echo "<option selected value='$noticia1[athlete_id]'>$noticia1[name]</option>"."<BR>";}
		else{echo  "<option value='$noticia1[athlete_id]'>$noticia1[name]</option>";}
		}
		echo "</select><input type=submit value=Submit></br>";
		echo "</form>";

	echo "<a href=''>View Individual Event Result</a></br>";
		$quer2=mysql_query("SELECT DISTINCT event FROM er1 order by event");
		// End of query for first list box

		echo "<form method=post name=f2 action='viewsingleevent.php'>";
		// Add your form processing page address to action in above line. Example  action=dd-check.php
		//Starting of first drop downlist 
		echo "<select name='sevent' onchange=\"reload(this.form)\"><option value=''>Select Event</option>";
		while($noticia2 = mysql_fetch_array($quer2)) { 
		if($noticia2['event']==@$cat){echo "<option selected value='$noticia2[event]'>$noticia2[event]</option>"."<BR>";}
		else{echo  "<option value='$noticia2[event]'>$noticia2[event]</option>";}
		}
		echo "</select><input type=submit value=Submit></br>";
		echo "</form></br>";

	echo "<a href=''>Contact Admin</a></br>";
	echo "</br>";
	
    echo '<form name="login-form" id="login-form" method="post" action="./index.php"> 
  <fieldset> 
  <legend>Admin Login</legend> 
  <dl> 
    <dt><label title="Username">Username: </label></dt> 
    <dd><input tabindex="1" accesskey="u" name="username" type="text" size="15" maxlength="15" id="username" /></dd> 
  </dl> 
  <dl> 
    <dt><label title="Password">Password: </label></dt> 
    <dd><input tabindex="2" accesskey="p" name="password" type="password" size="15" maxlength="15" id="password" /></dd> 
  </dl> 
  
  <p><input tabindex="3" accesskey="l" type="submit" name="cmdlogin" value="Login" ';
    if ($disabled == true)
    {
        echo 'disabled="disabled"';
    }
    echo ' /></p></fieldset></form>';
}

function show_changepassword_form(){
 
echo '<form action="./changepassword.php" method="post"> 
  <fieldset> 
  <legend>Change Password</legend> 
  <input type="hidden" value="'.$_SESSION['username'].'" name="username"> 
  <dl> 
    <dt> 
      <label for="oldpassword">Current Password:</label> 
    </dt> 
    <dd> 
      <input name="oldpassword" type="password" id="oldpassword" maxlength="15"> 
    </dd> 
  </dl> 
  <dl> 
    <dt> 
      <label for="password">New Password:</label> 
    </dt> 
    <dd> 
      <input name="password" type="password" id="password" maxlength="15"> 
    </dd> 
  </dl> 
  <dl> 
    <dt> 
      <label for="password2">Re-type new password:</label> 
    </dt> 
    <dd> 
      <input name="password2" type="password" id="password2" maxlength="15"> 
    </dd> 
  </dl> 
  <p> 
    <input name="reset" type="reset" value="Reset"> 
    <input name="change" type="submit" value="Reset Password"> 
  </p> 
  </fieldset> 
</form>
';
}
 

 
function show_lostpassword_form(){
 
	echo '<form action="./lostpassword.php" method="post"> 
	<fieldset><legend>Reset Password</legend>
  <dl> 
    <dt><label for="username">Username:</label></dt> 
    <dd><input name="username" type="text" id="username" maxlength="30">
    </dd> 
  </dl> 
   <dl> 
    <dt><label for="email">email:</label></dt> 
    <dd><input name="email" type="text" id="email" maxlength="255">
    </dd> 
  </dl> 
  <p> 
    <input name="reset" type="reset" value="Reset"> 
    <input name="lostpass" type="submit" value="Reset Password"> 
  </p> 
  </fieldset>
</form>';
 
}
 
function show_registration_form(){
 
	echo '<form action="./register.php" method="post"> 
	<fieldset><legend>Register</legend>
  <dl> 
    <dt><label for="username">Username:</label></dt> 
    <dd><input name="username" type="text" id="username" maxlength="30">
    </dd> 
  </dl> 
  <dl> 
    <dt><label for="password">Password:</label></dt> 
    <dd><input name="password" type="password" id="password" maxlength="15">
    </dd> 
  </dl> 
  <dl> 
    <dt><label for="password2">Re-type password:</label></dt> 
    <dd><input name="password2" type="password" id="password2" maxlength="15">
    </dd> 
  </dl> 
  <dl> 
    <dt><label for="email">email:</label></dt> 
    <dd><input name="email" type="text" id="email" maxlength="255">
    </dd> 
  </dl> 
  <p> 
    <input name="reset" type="reset" value="Reset"> 
    <input name="register" type="submit" value="Register"> 
  </p> 
  </fieldset>
</form>';
 
}

function show_add_athlete_form(){

	echo '<form action="./add_athlete.php" method="post"> 
	<fieldset><legend>Add New Athlete</legend>
  <dl> 
    <dt><label for="firstname">First Name:</label></dt> 
    <dd><input name="firstname" type="text" id="firstname" maxlength="30">
    </dd> 
  </dl> 
  <dl> 
    <dt><label for="lastname">Last Name:</label></dt> 
    <dd><input name="lastname" type="text" id="lastname" maxlength="15">
    </dd> 
  </dl> 
  <td><input type="checkbox" name="gender" id="gender[]" value="men" checked>Male
		<input type="hidden" name="checkboxm" value="0" />
	</td>
	<td><input type="checkbox" name="gender" id="gender[]" value="women">Female
		<input type="hidden" name="checkboxw" value="0" />
	</td>
  <p> 
    <input name="addathlete" type="submit" value="Add"> 
  </p> 
  </fieldset>
</form>';
 
}

function show_edit_athlete_form(){
	$id = $_GET['athlete_id'];
	$q = "SELECT id, firstname, lastname, gender FROM athlete WHERE id=$id";
	$r = mysql_query($q);	
		if (sqlNumRows($r) == 1) { // Valid user ID, show the form. 

		// Get the user's information:
		$row = sqlFetchArray ($r);
		//echo $row[3];
		//$aid = $row[3];
		//echo $aid;
		if($row['2'] == 'men') {
			//echo  'checkedm';

			 $t = 'checked';
		 } 
	}
		
		echo '<form action="./edit_athlete.php" method="post"> 
	<fieldset><legend>Edit Athlete</legend>
  <dl> 
    <dt><label for="firstname">First Name:</label></dt> 
    <dd><input name="firstname" type="text" id="firstname" value="' . $row[1] . '" maxlength="30">
    </dd> 
  </dl> 
  <dl> 
    <dt><label for="lastname">Last Name:</label></dt> 
    <dd><input name="lastname" type="text" id="lastname" value="' . $row[2] . '" maxlength="15">
    </dd> 
  </dl> 
  <td><input type="checkbox" name="gender" id="gender" value="men" >Male
  
		<input type="hidden" name="checkbox" value="0" />
		 
	</td>
	<td><input type="ch
<head>

      <script language="JavaScript" type="text/javascript">
		function jfunc(athlete,event,res)
		{
			//alert('made it here');
			alert(athlete);
			alert(event);
			alert(res);
		var result = document.getElementById('textres'+res).value;
		window.location='?action=UpdateResult&athlete_id='+athlete+'&event='+event+'&result='+result;
		}
      </script>  

</head>

<?php 
require_once ('includes/functions.php');
require_once ('includes/config.inc.php'); 
include ('header.php');

// Set the page title and include the HTML header:
$page_title = '';
//$url = BASE_URL . 'index.php';



?>


<div id="leftcolumn">
<?php include "sidebar.php"; ?>
<br/>	
</div>	
      
<div id="content_container">
		<div class="mcontent">
<?php


$e = isset($_POST['mevent']) ? $_POST["mevent"] : "";
/*
if (isset ($_POST['mevent'])){
$e=$_POST['mevent']; //gives event now
echo $e;
} else {
  //$e = "Push Ups";
  //echo $e;
} */

//$e=$_POST['mevent']; 



$query = "SELECT a.id, a.firstname, a.lastname, e.eorder, e.event, e1.result, e1.eventrank, e1.eventscore, e1.date, e1.id
			FROM
			er1 e1
			LEFT JOIN athlete a ON (e1.athlete_id = a.id)
			LEFT JOIN events e ON (e1.event = e.event)
			where e.event='$e'
			ORDER BY eventrank";
	
$res = mysql_query($query);
	if (!$res){
		die('Error with query: ' . mysql_error());
	}
	

$count=mysql_num_rows($res);
echo '<form name="list" action="mansignleeventr.php" method="post">';
// Table header:
echo '<table align="center" cellspacing="0" cellpadding="5" width="155%">
<tr>
	<td align="left"><b>FirstName</b></td>
	<td align="left"><b>LastName</b></td>
	<td align="left"><b>Event</b></td>
	<td align="left"><b>Results</b></td>
	<td align="left"><b>Rank</b></td>
	<td align="left"><b>Score</b></td>
	<td align="left"><b>Date</b></td>
</tr>';

// Fetch and print all the records....
#
$k = 1;
$bg = '#eeeeee'; 
while ($row = sqlFetchArray($res)) {
	$id[]=$row['id']; 
	//echo $row['event'];
	$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
	  echo '<tr bgcolor="' . $bg . '">
      <td align="left">' . $row['firstname'] . '</td>
      <td align="left">' . $row['lastname'] . '</td>
      <td align="left"><input name="event[]" id="event" value="' . $row['event'] . '" /></td>
      <td align="left"><input type="text" size="10" name="result[]" id="result" value="'.$row['result'].'" /></td>
      <td align="left">' . $row['eventrank']. '</td>
      <td align="left">' . $row['eventscore']. '</td>
      <td align="left">' . $row['date'] . '</td>
      
      </tr>';
	
	$k++;
	
	
} // End of WHILE loop.
echo '</table>';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';

?>

<?php
if(isset($_POST['Submit'])){//1
for($i=0;$i<$count;$i++){//2
	//echo $i;
	//$test = $_POST['result'];
	//echo $test;
	
	$r = $_POST['result'][$i];
	//echo $r; echo '</br>';
	
	$e = $_POST['event'][$i];
	//echo $e; echo '</br>';
	
	//$id = $_POST['athlete_id'][$i];
	//echo $id[$i]; echo '</br>';


	$sql = "UPDATE er1 set result='$r' WHERE event='$e' and id='$id[$i]'";
	//echo $sql; echo '</br>';
	
	//header("Location: index.php");	
	mysql_query($sql);
	$res = mysql_query($sql);
	if (!$res){//3
		die('Error with query: ' . mysql_error());
	}//3 
	
	
 //}
 }//2
}//1

?>
</div>
</div>	


<div id="footer">
<?php include ('footer.php'); ?>
</div>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.