Avatar of jroe6352
jroe6352
 asked on

Multiple Checkbox Form Help Needed

I need to allow users to use a checkbox to  make a change to multiple items in a mysql database - I'm a beginner at this and haven't found a good way to do this online.  I'm on a tight deadline and need to get this done.
<?PHP
require_once('../Connections/localhost.php');
mysql_select_db($database_localhost, $localhost);
//List Variables from Login Confirm Submission
$amerinetid = $_POST["amerinetid"];
$facilityname = $_POST["facilityname"];
$facilityaddress = $_POST["facilityaddress"];
$facilitycity = $_POST["facilitycity"];
$facilitystate = $_POST["facilitystate"];
$facilityzip = $_POST["facilityzip"];
$facilityphone = $_POST["facilityphone"];
/*Find any existing Media requests for this ID*/
$existingmediarequestquery = "SELECT inservicemedia.title, mediatransactions.mediatransaction_id, mediatransactions.firstdayneeded, mediatransactions.lastdayneeded FROM mediatransactions left join inservicemedia on inservicemedia.inservicemedia_id = mediatransactions.inservicemedia_id where mediatransactions.amerinetid = '$amerinetid'";
$existingmediarequestresult = mysql_query($existingmediarequestquery) or die(mysql_error());
$existingmediarequesttotal = mysql_num_rows($existingmediarequestresult);
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?PHP
	if(isset($_POST["confirm"]) && trim($_POST["confirm"])!=='') {
			//Check for Existing Media Reservations for this ID 
				if(0 == $existingmediarequesttotal) {
					echo "No Requests found for this Amerinet ID<br>" .
						 "<form action='reservechange.php' method='post'>" .				
						 "<input type='hidden' name='mediatitle' value='null'/>" .
						 "<input type='hidden' name='mediafirstday' value='null'/>" .
						 "<input type='hidden' name='medialastday' value='null'/>" .
						 "<input type='hidden' name='amerinetid' value='$amerinetid'/>" .
						 "<input type='submit' name='requestnew' value='Request New'/></form>";
					}
			//Show User the Information found in the database and Confirm Submission	
				else {
		 			echo "<form action='reservechange.php' method='post'>";
					while ($existingmedianamerequestrow = mysql_fetch_array($existingmediarequestresult, MYSQL_ASSOC))
					{
					echo "<input type='checkbox' name='mediacheckbox' value='{$existingmedianamerequestrow['mediatransaction_id']}' unchecked><input type='hidden' name='mediatitle' value='{$existingmedianamerequestrow['title']}'/>{$existingmedianamerequestrow['title']} reserved from <input type='hidden' name='mediafirstday' value='{$existingmedianamerequestrow['firstdayneeded']}'/>{$existingmedianamerequestrow['firstdayneeded']} until <input type='hidden' name='medialastday' value='{$existingmedianamerequestrow['lastdayneeded']}'/>{$existingmedianamerequestrow['lastdayneeded']}<input type='hidden' name='amerinetid' value='$amerinetid'><br>";
					}
					echo "<input type='hidden' name='amerinetid' value='$amerinetid'/>" .
			      		 "<input type='submit' name='cancelselected' value='Cancel Selected'/> <input type='submit' name='requestnew' value='Request New'/></form>";
		 }
	} else {
	//Redirect to the Original Form if this page is accessed directly
	echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../index.php">';
	exit;
		 }
?>
</body>
</html>

Open in new window

PHPMySQL Server

Avatar of undefined
Last Comment
jroe6352

8/22/2022 - Mon
jroe6352

ASKER
Recieving Page
<?PHP
require_once('../Connections/localhost.php');
require "../class.datepicker.php";
mysql_select_db($database_localhost, $localhost);
unset($amerinetid);
unset($mediaselect);
unset($begindate);
unset($enddate);
unset($medialink);
$amerinetid = $_POST["amerinetid"];
$query_medialist = "SELECT * FROM inservicemedia ORDER BY category ASC";
$medialist = mysql_query($query_medialist, $localhost) or die(mysql_error());
$row_medialist = mysql_fetch_assoc($medialist);
$totalRows_medialist = mysql_num_rows($medialist);
$dp=new datepicker();
//$mediacheckbox = $_POST["mediacheckbox"];
$mediatitle = $_POST["mediatitle"];
$mediafirstday = $_POST["mediafirstday"];
$medialastday = $_POST["medialastday"];
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?PHP
	//Check Incoming form for Button Pressed	
	if(isset($_POST["cancelselected"]) && trim($_POST["cancelselected"])!=='') {
	//They clicked cancel 
	
	
	
	
	echo "You clicked Cancel - THis area still being worked on"; 
	}                     
	
	
	
	
	elseif(isset($_POST["requestnew"]) && trim($_POST["requestnew"])!=='') {
    //they clicked Request New
	echo '<form id="mediareserve" name="mediareserve" method="post" action="submit.php">';
	echo 'Request Selection<br>';
	echo '<select name="mediaselect">';
    do {  
    echo '<option value="';
	echo $row_medialist['title'];
	echo '">';
	echo $row_medialist['title'];
	echo '</option>';
    } 
	while ($row_medialist = mysql_fetch_assoc($medialist));
  	$rows = mysql_num_rows($medialist);
  	if($rows > 0) {
    mysql_data_seek($medialist, 0);
	$row_medialist = mysql_fetch_assoc($medialist);
  	}
    echo '</select><br><br>';
	echo 'Beginning Date:<br>';
	echo '<input type="text" id="begindate" name="begindate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("begindate").'"><br><br>';
	
	echo 'Ending Date:<br>';
	echo '<input type="text" id="enddate" name="enddate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("enddate").'"><br><br>';
	
	echo '<input type="submit" name="chkavail" value="Check Availibility" />';
    echo '<input type="reset" name="Reset" value="Reset" />';
    echo '<input type="submit" name="Submit" value="Submit" /><br><p>';
	echo "<input type='hidden' name='amerinetid' value='$amerinetid'/></form>";
	   
	} 
	else {
	//Redirect to the Original Form if this page is accessed directly
	echo '<META HTTP-EQUIV="Refresh" Content="0; URL=iddata.php">';
	exit;
	}
?>
</body>
</html>

Open in new window

hernst42

See http://www.php.net/manual/en/faq.html.php#faq.html.select-multiple

you need to name the checkbox as name='mediacheckbox[]'

then $_POST['mediacheckbox'] is an array with selected checkboxes.
jroe6352

ASKER
Ok I've got that part done . . . But I'm just not wrapping my head around the code needed on the submit page . . .
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
jroe6352

ASKER
I've made some progress . . . but still seeing the error:

Notice: Undefined variable: mediacheckbox in /Library/WebServer/Documents/includes/reservechange.php on line 42
<?PHP
require_once('../Connections/localhost.php');
require "../class.datepicker.php";
mysql_select_db($database_localhost, $localhost);
unset($amerinetid);
unset($mediaselect);
unset($begindate);
unset($enddate);
unset($medialink);
unset($sql);
unset($todaydate);
unset($result);
unset($count);
$amerinetid = $_POST["amerinetid"];
$query_medialist = "SELECT * FROM inservicemedia ORDER BY category ASC";
$medialist = mysql_query($query_medialist, $localhost) or die(mysql_error());
$row_medialist = mysql_fetch_assoc($medialist);
$totalRows_medialist = mysql_num_rows($medialist);
$todaydate = date("Y-m-d");
$sql="SELECT * FROM mediatransactions";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$dp=new datepicker();
//$mediacheckbox = $_POST["mediacheckbox"];
$mediatitle = $_POST["mediatitle"];
$mediafirstday = $_POST["mediafirstday"];
$medialastday = $_POST["medialastday"];
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
<link href="shsc.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?PHP
	//Check Incoming form for Button Pressed	
	if(isset($_POST["cancelselected"]) && trim($_POST["cancelselected"])!=='') {
	//They clicked cancel 
    	for($i=0;$i<$count;$i++){
        $cncl_id = $mediacheckbox[$i];
		$sql = "UPDATE mediatransaction SET requestcancelled='1', requestcancellationdate='$todaydate' WHERE mediatransactionid='$cncl_id'";
		$result = mysql_query($sql);
	echo "You clicked Cancel - THis area still being worked on"; 
	}                     
	}	
	elseif(isset($_POST["requestnew"]) && trim($_POST["requestnew"])!=='') {
    //they clicked Request New
	echo '<form id="mediareserve" name="mediareserve" method="post" action="submit.php">';
	echo 'Request Selection<br>';
	echo '<select name="mediaselect">';
    do {  
    echo '<option value="';
	echo $row_medialist['title'];
	echo '">';
	echo $row_medialist['title'];
	echo '</option>';
    } 
	while ($row_medialist = mysql_fetch_assoc($medialist));
  	$rows = mysql_num_rows($medialist);
  	if($rows > 0) {
    mysql_data_seek($medialist, 0);
	$row_medialist = mysql_fetch_assoc($medialist);
  	}
    echo '</select><br><br>';
	echo 'Beginning Date:<br>';
	echo '<input type="text" id="begindate" name="begindate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("begindate").'"><br><br>';
	
	echo 'Ending Date:<br>';
	echo '<input type="text" id="enddate" name="enddate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("enddate").'"><br><br>';
	
	echo '<input type="submit" name="chkavail" value="Check Availibility" />';
    echo '<input type="reset" name="Reset" value="Reset" />';
    echo '<input type="submit" name="Submit" value="Submit" /><br><p>';
	echo "<input type='hidden' name='amerinetid' value='$amerinetid'/></form>";
	   
	} 
	else {
	//Redirect to the Original Form if this page is accessed directly
	echo '<META HTTP-EQUIV="Refresh" Content="0; URL=iddata.php">';
	exit;
	}
?>
</body>
</html>

Open in new window

jroe6352

ASKER
I think this is because I'm not "catching" the post for mediacheckbox . . . but I'm unsure how to do that with an array like this . . .
hernst42

You may not comment out:
//$mediacheckbox = $_POST["mediacheckbox"];

To loop over the checked checkboxes (only those are in $_POST) use

foreach ($mediacheckbox as $cncl_id) {
  $sql = ....
âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jroe6352

ASKER
That helped some, my errors are gone . . . but no changes take place in the database.
<?PHP
require_once('../Connections/localhost.php');
require "../class.datepicker.php";
mysql_select_db($database_localhost, $localhost);
unset($amerinetid);
unset($mediaselect);
unset($begindate);
unset($enddate);
unset($medialink);
unset($sql);
unset($todaydate);
unset($result);
unset($count);
$amerinetid = $_POST["amerinetid"];
$query_medialist = "SELECT * FROM inservicemedia ORDER BY category ASC";
$medialist = mysql_query($query_medialist, $localhost) or die(mysql_error());
$row_medialist = mysql_fetch_assoc($medialist);
$totalRows_medialist = mysql_num_rows($medialist);
$todaydate = date("Y-m-d");
$sql="SELECT * FROM mediatransactions";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$dp=new datepicker();
$mediacheckbox = $_POST["mediacheckbox"];
$mediatitle = $_POST["mediatitle"];
$mediafirstday = $_POST["mediafirstday"];
$medialastday = $_POST["medialastday"];
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
<link href="shsc.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?PHP
	//Check Incoming form for Button Pressed	
	if(isset($_POST["cancelselected"]) && trim($_POST["cancelselected"])!=='') {
	//They clicked cancel 
    	for($i=0;$i<$count;$i++){
        $cncl_id = $mediacheckbox[$i];
		foreach ($mediacheckbox as $cncl_id) {
		$sql = "UPDATE mediatransaction SET requestcancelled='1', requestcancellationdate='$todaydate' WHERE mediatransactionid='$cncl_id'";
		$result = mysql_query($sql);
		}
	echo "You clicked Cancel - THis area still being worked on"; 
	}                     
	}	
	elseif(isset($_POST["requestnew"]) && trim($_POST["requestnew"])!=='') {
    //they clicked Request New
	echo '<form id="mediareserve" name="mediareserve" method="post" action="submit.php">';
	echo 'Request Selection<br>';
	echo '<select name="mediaselect">';
    do {  
    echo '<option value="';
	echo $row_medialist['title'];
	echo '">';
	echo $row_medialist['title'];
	echo '</option>';
    } 
	while ($row_medialist = mysql_fetch_assoc($medialist));
  	$rows = mysql_num_rows($medialist);
  	if($rows > 0) {
    mysql_data_seek($medialist, 0);
	$row_medialist = mysql_fetch_assoc($medialist);
  	}
    echo '</select><br><br>';
	echo 'Beginning Date:<br>';
	echo '<input type="text" id="begindate" name="begindate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("begindate").'"><br><br>';
	
	echo 'Ending Date:<br>';
	echo '<input type="text" id="enddate" name="enddate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("enddate").'"><br><br>';
	
	echo '<input type="submit" name="chkavail" value="Check Availibility" />';
    echo '<input type="reset" name="Reset" value="Reset" />';
    echo '<input type="submit" name="Submit" value="Submit" /><br><p>';
	echo "<input type='hidden' name='amerinetid' value='$amerinetid'/></form>";
	   
	} 
	else {
	//Redirect to the Original Form if this page is accessed directly
	echo '<META HTTP-EQUIV="Refresh" Content="0; URL=iddata.php">';
	exit;
	}
?>
</body>
</html>

Open in new window

jroe6352

ASKER
If this error help I'm now getting this when submitting another form option:
Notice: Undefined index: mediacheckbox in /Library/WebServer/Documents/includes/reservechange.php on line 24
icarey

I have a form that allows users to select different options using many check boxes. I then pass these options to another php file that does all the handling and database inserts etc.
You may be able to adapt this code to your needs.

On the user input form:
echo "<tr>
              <td bgcolor=\"#336699\">
                <input type=\"checkbox\" name=\"medalnames[]\" value=\"$medid\" checked>
              </td>
              <td bgcolor=\"#b0c4de\">$medname</td>
        </tr>";

In the database handling php file to handle the name=\"medalnames[]\" above
            while (list ($medalekey, $medalival) = each ($medalnames))
                  {
                        $sqlmedali="INSERT INTO brstoremedali values ('$medalival', '$proveditid')";
                        $medaliresult=mysql_query($sqlmedali,$db)
                              or die(dberr());       
                  }//while (list ($medalekey, $medalival) = each ($medalnames))


Ivan
Your help has saved me hundreds of hours of internet surfing.
fblack61
jroe6352

ASKER
I have not been able to figure out how to make your code work icarey - I think perhaps this is just a bit above my level in php - can anyone try modifying my code?  I'm struggling to figure out how to understand the flow of this and how to modify my code to work with it.
icarey

jroe6352
In the top code snippet for your sending page I added [] after mediacheckbox
I think you did this any way.
I include this code below

<?PHP
require_once('../Connections/localhost.php');
mysql_select_db($database_localhost, $localhost);
//List Variables from Login Confirm Submission
$amerinetid = $_POST["amerinetid"];
$facilityname = $_POST["facilityname"];
$facilityaddress = $_POST["facilityaddress"];
$facilitycity = $_POST["facilitycity"];
$facilitystate = $_POST["facilitystate"];
$facilityzip = $_POST["facilityzip"];
$facilityphone = $_POST["facilityphone"];
/*Find any existing Media requests for this ID*/
$existingmediarequestquery = "SELECT inservicemedia.title, mediatransactions.mediatransaction_id, mediatransactions.firstdayneeded, mediatransactions.lastdayneeded FROM mediatransactions left join inservicemedia on inservicemedia.inservicemedia_id = mediatransactions.inservicemedia_id where mediatransactions.amerinetid = '$amerinetid'";
$existingmediarequestresult = mysql_query($existingmediarequestquery) or die(mysql_error());
$existingmediarequesttotal = mysql_num_rows($existingmediarequestresult);
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?PHP
      if(isset($_POST["confirm"]) && trim($_POST["confirm"])!=='') {
                  //Check for Existing Media Reservations for this ID
                        if(0 == $existingmediarequesttotal) {
                              echo "No Requests found for this Amerinet ID<br>" .
                                     "<form action='reservechange.php' method='post'>" .                        
                                     "<input type='hidden' name='mediatitle' value='null'/>" .
                                     "<input type='hidden' name='mediafirstday' value='null'/>" .
                                     "<input type='hidden' name='medialastday' value='null'/>" .
                                     "<input type='hidden' name='amerinetid' value='$amerinetid'/>" .
                                     "<input type='submit' name='requestnew' value='Request New'/></form>";
                              }
                  //Show User the Information found in the database and Confirm Submission      
                        else {
                               echo "<form action='reservechange.php' method='post'>";
                              while ($existingmedianamerequestrow = mysql_fetch_array($existingmediarequestresult, MYSQL_ASSOC))
                              {
                              echo "<input type='checkbox' name='mediacheckbox[]' value='{$existingmedianamerequestrow['mediatransaction_id']}' unchecked><input type='hidden' name='mediatitle' value='{$existingmedianamerequestrow['title']}'/>{$existingmedianamerequestrow['title']} reserved from <input type='hidden' name='mediafirstday' value='{$existingmedianamerequestrow['firstdayneeded']}'/>{$existingmedianamerequestrow['firstdayneeded']} until <input type='hidden' name='medialastday' value='{$existingmedianamerequestrow['lastdayneeded']}'/>{$existingmedianamerequestrow['lastdayneeded']}<input type='hidden' name='amerinetid' value='$amerinetid'><br>";
                              }
                              echo "<input type='hidden' name='amerinetid' value='$amerinetid'/>" .
                                     "<input type='submit' name='cancelselected' value='Cancel Selected'/> <input type='submit' name='requestnew' value='Request New'/></form>";
             }
      } else {
      //Redirect to the Original Form if this page is accessed directly
      echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../index.php">';
      exit;
             }
?>
</body>
</html>

I have altered the page that the above posts to. See below. You may have to check it for bugs but I was unable to test it with your code. I did test the basic code I added.

<?PHP
require_once('../Connections/localhost.php');
require "../class.datepicker.php";
mysql_select_db($database_localhost, $localhost);
unset($amerinetid);
unset($mediaselect);
unset($begindate);
unset($enddate);
unset($medialink);
unset($sql);
unset($todaydate);
unset($result);
unset($count);
$amerinetid = $_POST["amerinetid"];
$query_medialist = "SELECT * FROM inservicemedia ORDER BY category ASC";
$medialist = mysql_query($query_medialist, $localhost) or die(mysql_error());
$row_medialist = mysql_fetch_assoc($medialist);
$totalRows_medialist = mysql_num_rows($medialist);
$todaydate = date("Y-m-d");
$sql="SELECT * FROM mediatransactions";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$dp=new datepicker();
$mediacheckbox = $_POST["mediacheckbox"];
$mediatitle = $_POST["mediatitle"];
$mediafirstday = $_POST["mediafirstday"];
$medialastday = $_POST["medialastday"];
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
<link href="shsc.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?PHP
      //Check Incoming form for Button Pressed      
      if(isset($_POST["cancelselected"]) && trim($_POST["cancelselected"])!=='') {
      //They clicked cancel
             while (list ($mediakey, $mediaval) = each ($_POST["mediacheckbox"]))
            {
                $mediasql = "UPDATE mediatransaction SET requestcancelled='1', requestcancellationdate='$todaydate' WHERE mediatransactionid='$mediakey'";
                $result = mysql_query($mediasql);    
             }
            
      echo "You clicked Cancel - THis area still being worked on";                    
      }      
      elseif(isset($_POST["requestnew"]) && trim($_POST["requestnew"])!=='') {
    //they clicked Request New
      echo '<form id="mediareserve" name="mediareserve" method="post" action="submit.php">';
      echo 'Request Selection<br>';
      echo '<select name="mediaselect">';
    do {  
    echo '<option value="';
      echo $row_medialist['title'];
      echo '">';
      echo $row_medialist['title'];
      echo '</option>';
    }
      while ($row_medialist = mysql_fetch_assoc($medialist));
        $rows = mysql_num_rows($medialist);
        if($rows > 0) {
    mysql_data_seek($medialist, 0);
      $row_medialist = mysql_fetch_assoc($medialist);
        }
    echo '</select><br><br>';
      echo 'Beginning Date:<br>';
      echo '<input type="text" id="begindate" name="begindate">';
      
      echo '<input type="button" value="..." onclick="'.$dp->show("begindate").'"><br><br>';
      
      echo 'Ending Date:<br>';
      echo '<input type="text" id="enddate" name="enddate">';
      
      echo '<input type="button" value="..." onclick="'.$dp->show("enddate").'"><br><br>';
      
      echo '<input type="submit" name="chkavail" value="Check Availibility" />';
    echo '<input type="reset" name="Reset" value="Reset" />';
    echo '<input type="submit" name="Submit" value="Submit" /><br><p>';
      echo "<input type='hidden' name='amerinetid' value='$amerinetid'/></form>";
        
      }
      else {
      //Redirect to the Original Form if this page is accessed directly
      echo '<META HTTP-EQUIV="Refresh" Content="0; URL=iddata.php">';
      exit;
      }
?>
</body>
</html>

Ivan
jroe6352

ASKER
I've put in the code and I see the following error's on output and no update happens

You clicked Cancel - THis area still being worked on
Notice: Undefined offset: 1 in C:\Inetpub\vhosts\shsc-gpo.com\httpdocs\inservicemedia\includes\reservechange.php on line 50
You clicked Cancel - THis area still being worked on
Notice: Undefined offset: 2 in C:\Inetpub\vhosts\shsc-gpo.com\httpdocs\inservicemedia\includes\reservechange.php on line 50
You clicked Cancel - THis area still being worked on

âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jroe6352

ASKER
Updated code
<?PHP
// let's make sure the $_SERVER['DOCUMENT_ROOT'] variable is set
if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['SCRIPT_FILENAME'])){
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
}; };
if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['PATH_TRANSLATED'])){
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
}; };
// $_SERVER['DOCUMENT_ROOT'] is now set - you can use it as usual...
require_once('../Connections/localhost.php');
require "../class.datepicker.php";
mysql_select_db($database_localhost, $localhost);
unset($amerinetid);
unset($mediaselect);
unset($begindate);
unset($enddate);
unset($medialink);
unset($sql);
unset($todaydate);
unset($result);
unset($count);
$amerinetid = $_POST["amerinetid"];
$query_medialist = "SELECT * FROM inservicemedia ORDER BY category ASC";
$medialist = mysql_query($query_medialist, $localhost) or die(mysql_error());
$row_medialist = mysql_fetch_assoc($medialist);
$totalRows_medialist = mysql_num_rows($medialist);
$todaydate = date("Y-m-d");
$sql="SELECT * FROM mediatransactions";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$dp=new datepicker();
$mediacheckbox = $_POST["mediacheckbox"];
$mediatitle = $_POST["mediatitle"];
$mediafirstday = $_POST["mediafirstday"];
$medialastday = $_POST["medialastday"];
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
<link href="../shsc.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?PHP
	//Check Incoming form for Button Pressed	
	if(isset($_POST["cancelselected"]) && trim($_POST["cancelselected"])!=='') {
	//They clicked cancel 
	while (list ($mediakey, $mediaval) = each ($_POST["mediacheckbox"]))
    	{
        $mediasql = "UPDATE mediatransaction SET requestcancelled='1', requestcancellationdate='$todaydate' WHERE mediatransactionid='$mediakey'";
        $result = mysql_query($mediasql);    
        }
    echo "You clicked Cancel - THis area still being worked on";                    
    }     
	elseif(isset($_POST["requestnew"]) && trim($_POST["requestnew"])!=='') {
    //they clicked Request New
	echo '<form id="mediareserve" name="mediareserve" method="post" action="submit.php">';
	echo '<table border="1" class="selectioncss"><tr><td>';
	echo 'Request Selection<br>';
	echo '<select name="mediaselect">';
    do {  
    echo '<option value="';
	echo $row_medialist['title'];
	echo '">';
	echo $row_medialist['title'];
	echo '</option>';
    } 
	while ($row_medialist = mysql_fetch_assoc($medialist));
  	$rows = mysql_num_rows($medialist);
  	if($rows > 0) {
    mysql_data_seek($medialist, 0);
	$row_medialist = mysql_fetch_assoc($medialist);
  	}
    echo '</select><br><br>';
	echo 'Beginning Date:<br>';
	echo '<input type="text" class="begindatecss" id="begindate" name="begindate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("begindate").'"><br><br>';
	
	echo 'Ending Date:<br>';
	echo '<input type="text" class="enddatecss" id="enddate" name="enddate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("enddate").'"><p>';
	
	echo '<p><input type="submit" name="Submit" value="Submit" />';
    echo '<input type="reset" name="Reset" value="Reset" /><p></td></tr></table>';
	echo "<input type='hidden' name='amerinetid' value='$amerinetid'/></form>";
	   
	} 
	else {
	//Redirect to the Original Form if this page is accessed directly
	echo '<META HTTP-EQUIV="Refresh" Content="0; URL=iddata.php">';
	exit;
	}
?>
</body>
</html>

Open in new window

jroe6352

ASKER
I think I found part of my problem - It doesn't appear to be finding the $mediakey variable properly - if I do a echo It shows that as 0
ASKER CERTIFIED SOLUTION
icarey

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jroe6352

ASKER
Thanks - that improved my output as It now shows the right data variables in my echo but nothing in the database is updated . . .
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
icarey

try this
comment out
$mediacheckbox = $_POST["mediacheckbox"];
below the line $dp=new datepicker();

the problem may be a duplicate $result variable.
change $result = mysql_query($mediasql); to $mediaresult = mysql_query($mediasql); ensuring a new result set.
jroe6352

ASKER
No Change - Here is my updated code - I think I made the changes reccomended.
<?PHP
// let's make sure the $_SERVER['DOCUMENT_ROOT'] variable is set
if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['SCRIPT_FILENAME'])){
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
}; };
if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['PATH_TRANSLATED'])){
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
}; };
// $_SERVER['DOCUMENT_ROOT'] is now set - you can use it as usual...
require_once('../Connections/localhost.php');
require "../class.datepicker.php";
mysql_select_db($database_localhost, $localhost);
unset($amerinetid);
unset($mediaselect);
unset($begindate);
unset($enddate);
unset($medialink);
unset($sql);
unset($todaydate);
unset($result);
unset($count);
$amerinetid = $_POST["amerinetid"];
$query_medialist = "SELECT * FROM inservicemedia ORDER BY category ASC";
$medialist = mysql_query($query_medialist, $localhost) or die(mysql_error());
$row_medialist = mysql_fetch_assoc($medialist);
$totalRows_medialist = mysql_num_rows($medialist);
$todaydate = date("Y-m-d");
$sql="SELECT * FROM mediatransactions";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$dp=new datepicker();
//$mediacheckbox = $_POST["mediacheckbox"];
$mediatitle = $_POST["mediatitle"];
$mediafirstday = $_POST["mediafirstday"];
$medialastday = $_POST["medialastday"];
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
<link href="../shsc.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?PHP
	//Check Incoming form for Button Pressed	
	if(isset($_POST["cancelselected"]) && trim($_POST["cancelselected"])!=='') {
	//They clicked cancel 
	while (list ($mediakey, $mediaval) = each ($_POST["mediacheckbox"]))
    	{
		echo "'$todaydate', '$mediakey', '$mediaval' ";
        $mediasql = "UPDATE mediatransaction SET requestcancelled='1', requestcancellationdate='$todaydate' WHERE mediatransactionid='$mediaval'";
        $mediaresult = mysql_query($mediasql);    
        }
    echo "You clicked Cancel - THis area still being worked on";                    
    }     
	elseif(isset($_POST["requestnew"]) && trim($_POST["requestnew"])!=='') {
    //they clicked Request New
	echo '<form id="mediareserve" name="mediareserve" method="post" action="submit.php">';
	echo '<table border="1" class="selectioncss"><tr><td>';
	echo 'Request Selection<br>';
	echo '<select name="mediaselect">';
    do {  
    echo '<option value="';
	echo $row_medialist['title'];
	echo '">';
	echo $row_medialist['title'];
	echo '</option>';
    } 
	while ($row_medialist = mysql_fetch_assoc($medialist));
  	$rows = mysql_num_rows($medialist);
  	if($rows > 0) {
    mysql_data_seek($medialist, 0);
	$row_medialist = mysql_fetch_assoc($medialist);
  	}
    echo '</select><br><br>';
	echo 'Beginning Date:<br>';
	echo '<input type="text" class="begindatecss" id="begindate" name="begindate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("begindate").'"><br><br>';
	
	echo 'Ending Date:<br>';
	echo '<input type="text" class="enddatecss" id="enddate" name="enddate">';
	
	echo '<input type="button" value="..." onclick="'.$dp->show("enddate").'"><p>';
	
	echo '<p><input type="submit" name="Submit" value="Submit" />';
    echo '<input type="reset" name="Reset" value="Reset" /><p></td></tr></table>';
	echo "<input type='hidden' name='amerinetid' value='$amerinetid'/></form>";
	   
	} 
	else {
	//Redirect to the Original Form if this page is accessed directly
	echo '<META HTTP-EQUIV="Refresh" Content="0; URL=iddata.php">';
	exit;
	}
?>
</body>
</html>

Open in new window

icarey

Looks ok
Did you include all your mediatransaction table fields in the UPDATE statement?
âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jroe6352

ASKER
no I didn't . . . . I'll give that a try - I'm only looking to update those feilds and not the others . . . .
jroe6352

ASKER
I'm not seeing how to add other feilds that I don't want to modify . . . I did notice a typo - mediatransaction should be meditransactions - I updated that and still no change.
icarey

can you do an echo of the statement of $mediasql to see its output.
This may give a clue as to why the statement is not working. I am assuming that there is a  mediatransactionid the same as the $mediaval.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
jroe6352

ASKER
Sure

'2008-07-29', '0', '1'

'UPDATE mediatransactions SET requestcancelled='1', requestcancellationdate='2008-07-29' WHERE mediatransactionid='1''

You clicked Cancel - THis area still being worked on

icarey

can you place mysql_error() in
$mediaresult = mysql_query($mediasql) or die (mysql_error());
jroe6352

ASKER
That helped alot - I had another typo and that fixed it up - Thanks for all the help!
âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.