Forum Moderators: coopster

Message Too Old, No Replies

Cannot both submit data and redirect page with input button!

         

Spiceydog

10:42 pm on May 7, 2008 (gmt 0)

10+ Year Member



I have a web page with a simple HTML form input button that is supposed to submit data to a MySQL database AND bring you to a page to view the data. Unfortunatetly everytime I stick a simple action="schedule.php" into the <form> tag then the data is not submitted anymore but it does however redirect to the page I want.

Here is what I have in a nut shell:
<form method="post" name="schedule" action="schedule.php"><input name="btnSign" type="submit" value="Make Schedule"></form>

Thanks in advance!

LifeinAsia

10:48 pm on May 7, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What is the page that submits the data and what is the page that lets you view the data?

With the example you have, it should work if schedule.php submits the data then refreshes to the page that lets you view the data.

Spiceydog

11:18 pm on May 7, 2008 (gmt 0)

10+ Year Member



no schedule.php does not submit the data it is the page on which the input button is on that submits the data. the page that lets you view the data is schedule.php.

jatar_k

11:26 pm on May 7, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Spiceydog,

there's where your mess is

the action should be a php script that takes the posted data, saves it to the database and then redirects to the display page

one script can do all of those things

LifeinAsia

11:36 pm on May 7, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Then you need to change the form tag to submit to itself then refresh to schedule.php.

Spiceydog

1:19 am on May 8, 2008 (gmt 0)

10+ Year Member



all in the action, jatar? well that seems extremely confusing.
here is my entire input.php script (its where the form is and the input button aswell)

<html>
<head>
<title>Make Your Own Schedule</title>
<link href="schedule.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="left">
<h1><div class="titlez2"><center>Make a New Schedule:</center></div></h1>
<form method="post" name="schedule" action="">
<div class="labelz">Name:</div>
<div class="fieldz">
<input name="name" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Year at CFS:</div>
<div class="fieldz">
<input type="radio" name="year" value="Freshmen">Freshmen
<input type="radio" name="year" value="Sophomore">Sophomore
<input type="radio" name="year" value="Junior">Junior
<input type="radio" name="year" value="Senior">Senior
</div>
<div class="labelz">Adviser:</div>
<div class="fieldz">
<select name="adviser">
<option value="null" selected>--Select Your Adviser--</option>
<option value="Dave Worden">Dave Worden</option>
<option value="Rob LaVelle">Rob LaVelle</option>
<option value="Ken Mitchell">Ken Mitchell</option>
<option value="Frances Brindle">Frances Brindle</option>
<option value="Jamie Hysjulien">Jamie Hysjulien</option>
<option value="Bryce Little">Bryce Little</option>
<option value="Willy Rotella">Willy Rotella</option>
<option value="Elise London">Elise London</option>
<option value="Jon Lepofsky">Jon Lepofsky</option>
<option value="Susan Kincaid & Tim O'Hara">Susan Kincaid & Tim O'Hara</option>
<option value="Guillermo Parra">Guillermo Parra</option>
<option value="Amelia Shull">Amelia Shull</option>
<option value="Carrie Huff">Carrie Huff</option>
</select>
</DIV>
<div class="labelz">First Period:</div>
<div class="fieldz">
<input name="first" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Second Period:</div>
<div class="fieldz">
<input name="second" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Third Period:</div>
<div class="fieldz">
<input name="third" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Fourth Period:</div>
<div class="fieldz">
<input name="fourth" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Fifth Period:</div>
<div class="fieldz">
<input name="fifth" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Sixth Period:</div>
<div class="fieldz">
<input name="sixth" type="text" size="50" maxlength="30">
</div>
<div class="labelz">Seventh Period:</div>
<div class="fieldz">
<input name="seventh" type="text" size="50" maxlength="30">
</div>
<div class="labelz">Eighth Period:</div>
<div class="fieldz">
<input name="eighth" type="text" size="50" maxlength="30">
</div>
<div class="titlez1"><center><input name="btnSign" value="Make Schedule" type="submit"></center></div></form></div>
<?php

include 'login.php';

if(isset($_POST['btnSign']))
{
include 'login.php';

$name = trim($_POST['name']);
$adviser = trim($_POST['adviser']) OR DIE ("MESSAGE!");
$year = trim($_POST['year']);
$first = trim($_POST['first']);
$second = trim($_POST['second']);
$third = trim($_POST['third']);
$fourth = trim($_POST['fourth']);
$fifth = trim($_POST['fifth']);
$sixth = trim($_POST['sixth']);
$seventh = trim($_POST['seventh']);
$eighth = trim($_POST['eighth']);

{
$query = "INSERT INTO schedule(name, year, adviser, first, second, third, fourth, fifth, sixth, seventh, eighth) VALUES ('$name', '$year', '$adviser', '$first', '$second', '$third', '$fourth', '$fifth', '$sixth', '$seventh', '$eighth')";
}
{
mysql_query($query) or die('YOUR FIELD WAS TO LONG!');

//header('Location: ' . $_SERVER['REQUEST_URI']);
exit;
} }
?>
</body>
</html>

[edited by: jatar_k at 1:30 am (utc) on May 8, 2008]
[edit reason] inserted code [/edit]

Spiceydog

1:33 am on May 8, 2008 (gmt 0)

10+ Year Member



thanks for moving and editting my post jatar!

jatar_k

12:18 pm on May 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the form action would need to be set to itself

then you would need to uncomment this line
//header('Location: ' . $_SERVER['REQUEST_URI']);

but I think you would need to have your display script in there like so

header('Location: schedule.php');

though the above only works if schedule.php is in the same directory as the form

Spiceydog

3:16 pm on May 8, 2008 (gmt 0)

10+ Year Member



Alright I did what you said jatar and now I am getting the error:
Warning: Cannot modify header information - headers already sent by (output started at /home/pv3/public_html/school/input.php:9) in /home/pv3/public_html/school/input.php on line 125

Line 125 is:
header('Location: schedule.php');

LifeinAsia

3:27 pm on May 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



My guess is that you need to put
if(isset($_POST['btnSign']))
{
include 'login.php';

$name = trim($_POST['name']);
...
} }

all above the <html> tag.

[edited by: LifeinAsia at 3:27 pm (utc) on May 8, 2008]

Spiceydog

3:51 pm on May 8, 2008 (gmt 0)

10+ Year Member



It turned out I just needed to stick everything above the <html> tag! and it all works great now! thanks!