Page 1 of 2

different pages depending on button clicked

Posted: Tue Dec 22, 2009 10:55 am
by ryan1987
hi

i have a html page with a form. you enter information into the form then have a choice of 2 buttons. depending on the button you press you get taken to a different page. the php page commits the data you put into he form to the database then after 5 seconds should take you to the page you want.
I have attached my php code but i get the following 3 errors:


Notice: Undefined index: Add Another Team in C:\wamp\www\addteam.php on line 11

Notice: Undefined index: Finish Adding Teams in C:\wamp\www\addteam.php on line 14

Not Found

The requested URL /<br /><b>Notice</b>: Undefined variable: page in <b>C:\wamp\www\addteam.php</b> on line <b>3</b><br /> was not found on this server.

please can you help me fix this error. I am new to php and cannot figure it out

php code:

<html>
<head>
<META HTTP-EQUIV="refresh" CONTENT="5;URL=<?php echo $page; ?>">
<title>Football League</title>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>
<body>

<?php

if ($_POST['Add Another Team'])
{
$page = addteam.html; }
else if ($_POST['Finish Adding Teams']) {
$page = index.html; }

?>
<div id="contain">
<div id="header">
<div id="logo">
<h1>Football League Database</h1>
</div>

<div id="menu">
<ul>
<li class="first"><a href="index.html">Home</a></li>
<li><a href="addteam.html">Create League/Cup</a></li>
<li><a href="statistics.html">View Statistics</a></li>
<li><a href="fixtures.html">View/Update Fixtures</a></li>
</ul>
</div>
</div>

<div id="page">
<div id="content">
<h1>Your have entered the following details:</h1>
<div class="header">

<?php

//MySQL Database Connect
include 'dblogin.php';

//Retreve data from form
$teamname = "$_POST[teamname]";
$teammanager = "$_POST[teammanager]";

//Insert SQL Statement
$query = "insert into team (name, manager) values (trim('$teamname'), trim('$teammanager'))";

if (!mysql_query($query,$conn))
{
die('Error: ' . mysql_error());
}

echo"
<html>
<table>
<tr>
<td>Team Name: </td>
<td>$teamname</td>
</tr>
<tr>
<td>Team Manager: </td>
<td>$teammanager</td>
</tr>
</table>
</html>
";

print "You will be redirect in 5 seconds<br>";

mysql_close($conn);

?>
</div>
</div>
</div>
</body>
</html>

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 12:04 pm
by ryan1987
can someone help please?

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 12:39 pm
by manohoo
Please post the file with the <form>, so that we can take a closer look.

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 12:58 pm
by ryan1987
this is the page with the form. please note the javascript currently isint working properly

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Football League</title>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<SCRIPT TYPE="text/javascript">
function setbg(color)
{
document.getElementById("teamname").style.background=color
}

function Length_TextField_Validator()
{
// Check the length of the value of the teamname and teammanager
if ((addteam.teamname.value.length < 3) || (addteam.teamname.value.length > 20))
{
// alert box message
mesg = "You have entered " + addteam.teamname.value.length + " character(s)\n"
mesg = mesg + "Valid entries are between 3 and 20 characters for team name.\n"
alert(mesg);
// Place the cursor on the field
addteam.teamname.focus();
// return false to stop user going any further
return (false);
}
else if ((addteam.teamamanger.value.length < 3) || (addteam.teammanager.value.length > 20))
{
mesg = "You have entered " + addteam.teammanager.value.length + " character(s)\n"
mesg = mesg + "Valid entries are between 3 and 20 characters for team manager\n"
alert(mesg);
// Place the cursor on the field
addteam.teammanager.focus();
// return false to stop user going any further
return (false);
}
else {
// If teamname and teammanager is not null continue processing
return (true);
}
}

</SCRIPT>

</head>
<body>

<div id="contain">
<div id="header">
<div id="logo">
<h1>Football League Database</h1>
</div>

<div id="menu">
<ul>
<li class="first"><a href="index.html">Home</a></li>
<li><a href="addteam.html">Create League/Cup</a></li>
<li><a href="statistics.html">View Statistics</a></li>
<li><a href="fixtures.html">View/Update Fixtures</a></li>
</ul>
</div>
</div>

<div id="page">
<div id="content">
<div class="header">
<h1>The First Step is to create the teams</h1>
<h1>Please fill in the details below</h1>
</div>
<div class="header">
<form name="addteam" method="post" action="addteam.php" onSubmit="return Length_TextField_Validator()">
<Table>
<tr>
<td>Team Name: </td>
<td><input name="teamname" type="text" onFocus="setbg('#cccccc');" onBlur="setbg('white')" value="" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Team Manager: </td>
<td><input name="teammanager" type="text" onFocus="setbg('#cccccc');" onBlur="setbg('white')" onClick="setbg('#cccccc');" size="30" maxlength="30"></td>
</tr>
<tr>
<td> <input type="submit" name="addteam" value="Add Another Team" /> </td>
<td> <input type="submit" name="finishadding" value="Finish Adding Teams" /> </td>
</tr>
</table>
</form>
</div>
</div>
</div>

</div>
</div>
</body>
</html>

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 1:16 pm
by manohoo
instead of:
if ($_POST['Add Another Team'])

try this:
if ($_POST['addteam'])

Let me know what happens

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 1:27 pm
by ryan1987
i still get the error below after 5 seconds:

Not Found

The requested URL /<br /><b>Notice</b>: Undefined variable: page in <b>C:\wamp\www\addteam.php</b> on line <b>3</b><br /> was not found on this server.

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 1:58 pm
by manohoo
I noticed another thing. You can't process a submitted form in HTML, the file should be addteam.php.

instead of:
$page = addteam.html;
do this:
$page = addteam.php;

and rename addteam.html to addteam.php

Let me know what happens

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 2:10 pm
by ryan1987
thanks for helping me but i am not sure what you mean.

when you click one of the buttons on my html page it takes you to the php page. the php page then does some processesing and then should take you back to 1 of the 2 html pages.

hope that explains my situation a bit better

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 2:31 pm
by manohoo
Just for learning purposes, do me a favor.
Create 2 files:
test.php and test.html

In both files include this code:
<html>
<head> </head>
<body> <?php echo "hello there!"; ?> </body>
</html>

Open both files with any browser, what do you notice?

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 2:47 pm
by ryan1987
in the html file i see this: In both files include this code:

in the php file is see this In both files include this code: hello there!

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 3:05 pm
by manohoo
Exactly.

When working with PHP and HTML code stick with PHP files only.

Another thing, review your code, I saw some instances where text variables were not properly defined. For instance:

$page = addteam.html; }
else if ($_POST['Finish Adding Teams']) {
$page = index.html

should be:
$page = "addteam.html"; }
else if ($_POST['Finish Adding Teams']) {
$page = "index.html";

AND

$teamname = "$_POST[teamname]";
$teammanager = "$_POST[teammanager]";

should be:
$teamname = $_POST['teamname'];
$teammanager = $_POST['teammanager'];

I am sure you will find more errors similar to the above.
Good luck!

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 3:13 pm
by ryan1987
i have made those changes you recommend and it did fix anything.
it actually gave me to additional errors:

Notice: Use of undefined constant teamname - assumed 'teamname' in C:\wamp\www\addteamprocess.php on line 47

Notice: Use of undefined constant teammanager - assumed 'teammanager' in C:\wamp\www\addteamprocess.php on line 48

line 47 and 48 is this:

$teamname = $_POST[teamname];
$teammanager = $_POST[teammanager];

when they were in "" i didnt get this error

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 3:17 pm
by daedalus__
you both need to use [syntax=php][/syntax] tags. i mean it.

also

<META HTTP-EQUIV="refresh" CONTENT="5;URL=<?php echo $page; ?>">

there is line 3. what did the error say? could not find variable named $page blah blah. why? because you haven't assigned it a value. have you?

read the error messages and try to understand them or hire someone to debug your code.

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 3:19 pm
by daedalus__
read this real carefully and think about what he said
manohoo wrote:

Code: Select all

 
$teamname = "$_POST[teamname]";
$teammanager = "$_POST[teammanager]";
 
should be:
$teamname = $_POST['teamname'];
$teammanager = $_POST['teammanager'];
 
what did you change it to?

Code: Select all

 
$teamname = $_POST[teamname];
$teammanager = $_POST[teammanager];
 
what should it be?

Code: Select all

 
$teamname = $_POST["teamname"];
$teammanager = $_POST["teammanager"];
 
read the language reference in the manual.

http://us3.php.net/manual/en/language.basic-syntax.php

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 3:25 pm
by ryan1987
i do assign something to $page here:

Code: Select all

 
<?php 
if ($_POST['Add Another Team'])
{
    $page = "addteam.html"; } 
    else if ($_POST['Finish Adding Teams']) {
    $page = "index.html"; }
 
?>
 
could you help me try and find a solution to this error?