I should be able to pass variables between to HTML forms if I use the same variables on both of the pages ....correct??

My pages are:

Page 1

<?php

include_once('dbconnect.php');

//        Set up query
//        NOTE:  Temporarily set the limit to 5 during testing.

$query = 'select id, event, DATE_FORMAT( startdate, "%M %d, %Y" ) as sd,
         DATE_FORMAT( enddate, "%M %d, %Y" ) as ed, sponsor, location,
         contact, comments from events where status = 0 order by startdate ';

$result = mysql_query( $query ) or die(mysql_error());

//        These are the messages that get sent when a calendar item is approved or disapproved.
$message = '<p>This is a test message for approval</p>';
$message2 = '<p>This is a test for disapproval</p>';

echo '
        <h1>Calendar Administration</h1>';

echo '
        <table width="100%" border="1">
        <tr>
                <td><strong>Event</strong></td>
                <td><strong>Start Date</strong></td>
                <td><strong>End Date</strong></td>
                <td><strong>Sponsor</strong></td>
                <td><strong>Location</strong></td>
                <td><strong>Contact Person</strong></td>
                <td><strong>Comments</strong></td>
                <td colspan="3"><strong>Status</strong></td>
        </tr>
        <tr>';

while ( $value = mysql_fetch_assoc( $result ))
        {

            //        All but the last column simply display data.

            echo "<td>$value[event]</td>";
            echo "<td>$value[sd]</td>";
            echo "<td>$value[ed]</td>";
            echo "<td>$value[sponsor]</td>";
            echo "<td>$value[location]</td>";
            echo "<td>$value[contact]</td>";
            echo "<td>$value[comments]</td>";
            echo "<td>$value[status]</td>";

            //        Final column has the Approve / Disapprove stuff
            if ( $_REQUEST['action'] == 'Approve' and (int)($_REQUEST['calendar_ID']) == $value['id'] )
            {
                    //        They hit the approve button for this row
                    //        Send the approval email and notify user.

                    mail($_REQUEST['email'], $value['event'], $message,
                    "From: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
                    "Reply-To: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
                    "X-Mailer: PHP/" . phpversion());
                    print('<td>Approval sent.</td>');
                    $sql = 'UPDATE events SET status = 1 WHERE ID = $_REQUEST[calendar_id] or die(mysql_error() )';
            }
            elseif ( $_REQUEST['action'] == 'Disapprove' and (int)($_REQUEST['calendar_ID']) == $value['id'] )
            {
                    //        They hit the disapprove button for this row
                    //        Send the disapproval email and notify user.

                    mail($_REQUEST['email'], $value['event'], $message2,
                    "From: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
                    "Reply-To: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
                    "X-Mailer: PHP/" . phpversion());
                    print('<td>Disapproval sent.</td>');
                    $sql2 = 'UPDATE events SET status = \'2\' WHERE ID = $_REQUEST[calendar_id] or die(mysql_error() )';
            }
            //They hit the edit button for this row
            //Redirects to editevents.php for admin changes
            elseif ( $_REQUEST['action'] == 'Edit Event' and (int)($_REQUEST['calendar_ID']) == $value['id'] )
            {
             header("Location: editevents.php");
             }
            else
            {
                      //        Just normal display for this row
                    //        Display the option to approve or disapprove.

                    echo '
                    <td>
                            <form method="post" action="' . $_SERVER['PHP_SELF'] . '">
                                    <input type="hidden" name="calendar_ID" value="' . $value['id'] . '" />
                                    <input type="hidden" name="email" value="stevec@nmsu.edu" />
                                    <input type="submit" name="action" value="Approve" />
                                    <input type="submit" name="action" value="Disapprove" />
                                    <input type="submit" name="action" value="Edit Event" />
                            </form>
                    </td>';
            }

            echo '
    </tr>';
     }
echo '
</table>';
echo '<a href="../index.php">Home</a>&nbsp;§&nbsp;<a href="index.php">Calendar Administration</a>';

?>

Page 2

<?php

include_once( 'dbconnect.php' );


echo'<h1>Edit Event</h1>
     <form action="editevents.php" method="post">
     <table>
     <th align=center colspan=2>Enter your event information in the form below:</th>';

$result = mysql_query( "select *, DATE_FORMAT( startdate, '%M %d, %Y' ) as sd,
         DATE_FORMAT( enddate, '%M %d, %Y' ) as ed from events where '$calendar_ID' = '$_GET[id]' " );

echo"<tr><td><b>Title:</b></td>";
echo"<td><input type=text name=startdate size=30 maxlength=30 value= '$value[title]' /></td></tr>";
echo"<tr><td><b>Start Date:</b></td>";
echo"<td><input type=text name=startdate size=30 maxlength=30 value= '$value[sd]' /></td></tr>";
echo"<tr><td><b>End Date:</b></td>";
echo"<td><input type=text name=enddate size=30 maxlength=30 value= '$value[ed]' /></td></tr>";
echo"<tr><td><b>Event:</b></td>";
echo"<td><input type=text name=event size=30 maxlength=30 value= '$value[event]' /></td></tr>";
echo"<tr><td><b>Location:</b></td>";
echo"<td><input type=text name=location size=30 maxlength=30 value= '$value[location]' /></td></tr>";
echo"<tr><td><b>Sponsor:</b></td>";
echo"<td><input type=text name=location size=30 maxlength=30 value= '$value[sponsor]' /></td></tr>";
echo"<tr><td><b>Contact Person</b></td>";
echo"<td><input type=text name=contact size=30 maxlength=30 value= '$value[contact]' /></td></tr>";
echo"<tr><td><b>Your Phone:</b></td>";
echo"<td><input type=text name=phone size=30 maxlength=30 value= '$value[phone]' /></td></tr>";
echo"<tr><td><b>Email:</b></td>";
echo"<td><input type=text name=email size=30 maxlength=30 value= '$value[email]' /></td></tr>";
echo"<tr><td><b>Submitted By:</b></td>";
echo"<td><input type=text name=submittername size=30 maxlength=30 value= '$value[submittername]' /></td></tr>";
echo"<tr><td><b>Phone:</b></td>";
echo"<td><input type=text name=submitterphone size=30 maxlength=30 value= '$value[submitterphone]' /></td></tr>";
echo"<tr><td><b>Email</b></td>";
echo"<td><input type=text name=submitteremail size=30 maxlength=30 value= '$value[submitteremail]' /></td></tr>";
echo"<tr><td><b>Comments</b></td>";
echo"<td><textarea cols=22 rows=5 name=comments value= '$value[comments]' >$value[comments]</textarea></td></tr>";

echo'<tr>
     <td align="center" colspan="2">

 <input type="submit" name="submit" value="Update Record" />&nbsp;&nbsp;
 <input type="reset" name="action" value="Clear Form" /></td>';
echo'</tr>
     </table>
     </form>';

if( $_POST['submit'] )
{
$sql = mysql_query("update events set
title = '$value[title]',
startdate = '$value[sd]',
enddate = '$value[ed]',
event = '$value[event]',
location = '$value[location]',
sponsor = '$value[sponsor]',
contact = '$value[contact]',
phone = '$value[phone]',
email = '$value[email]',
submittername = '$value[submittername]',
submitterphone = '$value[submitterphone]',
submitteremail = '$value[submitteremail]',
comments = '$value[comments]'
where id = '$value[id]' ");
printf("Record updated successfully: %d\n", mysql_affected_rows() );
} else {
echo '<p><font color = "red" >Your record could not be updated. ' . mysql_error() . '<br />
We appologize for any inconvenience.<br /> Please try again</font></p>';
}
//End of Form
//Update record with new information
?>

When I am looking at the second page, I have either undefined variables or undefined indexes?

What am I overlooking??

    Ok, this is assuming that page two is editevents.php...

    When you view this page by using the location header (ie. header("Location: editevents.php"); ) you loose any request data that you have.

    To fix this, you could just include the the editevents.php and call exit() or return right afterwards, and that way you'll still have access to all of the variables you had on the including page.

    I'm not sure if you can pass a query string when you do the Location: editevents.php, but if you can that would work as well.

    Hope that helps!

    Erestar

      My issue now is I can't get the correct row from events_index.php.

      No matter which event i want to edit, my query gives me the first record in the database.

      I tried to pass the calendar_ID to = the database id, but i get an error.

        What error are you getting? Remember when you pass in things to a where clause you need to account for type, so if, in your database, ID is an number (like an integer) you'd do something like

        where ID=$id

        but if its a string you of some type, you'd do

        where ID='$id'

        Erestar

          This is my new select query:

          $result = mysql_query( "select *, DATE_FORMAT( startdate, '%M %d, %Y' ) as sd,
          DATE_FORMAT( enddate, '%M %d, %Y' ) as ed from events where id = 'value['id']'limit 1" );

          this is the error message i am getting

          Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Library/WebServer/Documents/Cahe/eventscopy/admin/events_index.php on line 78

            Originally posted by nmphpwebdev
            where id = 'value['id']'limit 1" );

            Your problem is here, I think... You're nesting too many single quote values in there. Remember that PHP strings and SQL strings are both using quotes, so to get them to SQL correctly you may need to escape them in PHP, or break out of the string.

            Here's how I'd rewrite that last part:
            The ... below represents the string up to that point, so there should have been an opening " at the start of the string.

            ...  where id ='".$value['id']."' limit 1");
            
              Write a Reply...