I have this chronic problem with my php file, though I have made a lot research about the submit buttons and isset and $_POST part of the problem still persist. For you to understand and probably point out my mistakes, i have enclosed the script below:

<?php
$m = (!$m) ? date("m",mktime()) : "$m";
$y = (!$y) ? date("Y",mktime()) : "$y";

if (($_SERVER['REQUEST_METHOD'] == "POST") || ($_SERVER['Submit7'] == "Next"))
{
$eventdate = $_POST['eventdate'];
$stime = $_POST['stime'];
$location = $_POST['locate'];
$mdescription = $_POST['description'];

header('location:next.php');
exit();
}else if (($_SERVER['REQUEST_METHOD'] == "POST") || ($_SERVER['Submit6'] == "Reset"))
{
header('location: myfile.php');
exit();
}

?>
<html>
<table>
<tr>
<!-- calling the function to draw the calendar -->
<td valign="top"><?php cal($_GET['m'],$_GET['y']); ?></td>
<td width="25" nowrap><br /></td>
<td> </td>
<td>
<!-- the second column of the table starts here -->
<!-- -->
<form name="me" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
<table cellpadding="4" cellspacing="1" border="0 "bgcolor="#FFFFFF">
<tr><td colspan="2" bgcolor="#3399FF"><font size="+1" color="#FFFFFF"><b>Request Form</b></font></td></tr>
<tr><td><b>Date for Event: </b></td><td><input type="text" name="eventdate" value="" size="12"> <font size="2">dd/mm/yyyy</font></td></tr>
<tr>
<td><b>Start Time:</b></td>
<td><input type="text" name="stime"> 24 Hour Format ie.1125 </td>
</tr>
<tr>
<td><b>Location:</b></td>
<td><input type="text" name="locate">20 Characters</td>
</tr>
<tr>
<td><b> Description:</b></td>
<td><textarea name="descrption"></textarea></td>
</tr>
<tr>
<td colspan="2" bgcolor="#3399FF"><div align="center">
<input type="submit" name="Submit6" method="POST" value="Reset"> &nbsp; &nbsp; &nbsp; &nbsp;
<input type="submit" method="post" name="Submit7" value="Next">
</td>
</tr>
</table></form>
</table>
</blockquote>
</body>
</html>
<?php>

the problem is with processing the reset and next buttons - I have tried several options and neither solves the problem.

Make sure you put your code in code tags.

if (($_SERVER['REQUEST_METHOD'] == "POST") || ($_SERVER['Submit7'] == "Next"))
{
$eventdate = $_POST['eventdate'];
$stime = $_POST['stime'];
$location = $_POST['locate'];
$mdescription = $_POST['description'];

header('location:next.php');
exit();
}

Would it not be better to replace the IF statement with

if (isset($_POST['Submit7'])) {

This will check whether the submit button has been clicked, also I don't believe $_SERVER can be used to check form fields, check http://uk3.php.net/manual/en/reserved.variables.server.php.

Also, can I ask why you aren't using the reset button in HMTL? <input type="reset"> as this will clear all fields in the form.

Make sure you put your code in code tags.

if (($_SERVER['REQUEST_METHOD'] == "POST") || ($_SERVER['Submit7'] == "Next"))
{
$eventdate = $_POST['eventdate'];
$stime = $_POST['stime'];
$location = $_POST['locate'];
$mdescription = $_POST['description'];

header('location:next.php');
exit();
}

Would it not be better to replace the IF statement with

if (isset($_POST['Submit7'])) {

This will check whether the submit button has been clicked, also I don't believe $_SERVER can be used to check form fields, check http://uk3.php.net/manual/en/reserved.variables.server.php.

Also, can I ask why you aren't using the reset button in HMTL? <input type="reset"> as this will clear all fields in the form.

Thanks for the reply, I must admit i am a beginner and having tried so many options had gotten me eventually confused.

will try your options and get back ASAP

Hi Xan,

I have worked on the script after your last input and have changed the $_SERVER to:

if(isset($submit)== 'Next')
 {
 	$eventdate = $_POST['eventdate']; 
		$stime = $_POST['stime'];
		$location = $_POST['locate'];
		$mdescription = $_POST['description'];
		}

The reset works, but when I click on the next button, it seems to function just like the reset.

Not quite

$_POST is the item to use for the if statement.

What this does is gets the value for the field in the form which is named in quotes.

You don't need anything but <input type="submit" name="Submit7" value="Next" /> for the submit button, the method=post is defined by the <form> tag.

All you need for the if statement is the code I posted earlier, if (isset($_POST['Submit7'])) { this says 'If Submit7 has been pressed, run the following code'.

Thanks Xan, I now have an understanding of how the implementation should be, however, after several trials the next button seem only reset the page. could it be a prblem with the form tag?
1. <form name="me" action="<?php echo $_SERVER; ?>" method="POST">

I changed it to
2. <form name="me" method="POST" action="<? echo $PHP_SELF; ?> > and the error after submitting the next button is
Forbidden
You don't have permission to access /myclass/< on this server.

Dont you think am not doing something right?

sorry for being a pain.

I have broken up the code with the required changes as below:

<?php
$m = (!$m) ? date("m",mktime()) : "$m";
$y = (!$y) ? date("Y",mktime()) : "$y";

Changes Here

if (isset($_POST['Submit7']))
{
$eventdate = $_POST['eventdate'];
$stime = $_POST['stime'];
$location = $_POST['locate'];
$mdescription = $_POST['description'];

header('location:next.php');
exit();
}

Remove reset code

?>
<html>
<table>
<tr>
<!-- calling the function to draw the calendar -->
<td valign="top"><?php cal($_GET['m'],$_GET['y']); ?></td>
<td width="25" nowrap><br /></td>
<td> </td>
<td>
<!-- the second column of the table starts here -->
<!-- -->
<form name="me" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
<table cellpadding="4" cellspacing="1" border="0 "bgcolor="#FFFFFF">
<tr><td colspan="2" bgcolor="#3399FF"><font size="+1" color="#FFFFFF"><b>Request Form</b></font></td></tr>
<tr><td><b>Date for Event: </b></td><td><input type="text" name="eventdate" value="" size="12"> <font size="2">dd/mm/yyyy</font></td></tr>
<tr>
<td><b>Start Time:</b></td>
<td><input type="text" name="stime"> 24 Hour Format ie.1125 </td>
</tr>
<tr>
<td><b>Location:</b></td>
<td><input type="text" name="locate">20 Characters</td>
</tr>
<tr>
<td><b> Description:</b></td>
<td><textarea name="descrption"></textarea></td>
</tr>
<tr>
<td colspan="2" bgcolor="#3399FF"><div align="center">

Changes Here

<input type="reset" name="Submit6" value="Reset"> &nbsp; &nbsp; &nbsp; &nbsp;
<input type="submit" name="Submit7" value="Next">
</td>
</tr>
</table></form>
</table>
</blockquote>
</body>
</html>

This should do what you want.

Xan,

Many regards, its working perfectly - each of the buttons are doing what they are meant to.

going to beef it up with the needed items.

Thanks

No problem, make sure you mark finished topics as solved :)

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.