different pages depending on button clicked
Moderator: General Moderators
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: different pages depending on button clicked
you have to initialize a variable before you use it. which you would know, if you read the language reference. like i told you to.
problem solved. that will be fifty dollars.
problem solved. that will be fifty dollars.
Re: different pages depending on button clicked
you dont have to speak to me like that i am only asking for help
i thought in php you dont have the initialize variables?
anyway i put to initialize it and it still didnt work
i thought in php you dont have the initialize variables?
anyway i put
Code: Select all
$page = "";Re: different pages depending on button clicked
Sorry daedalus. it's my first time day in this forum and I did not know the protocol.
Code: Select all
Re: different pages depending on button clicked
The $_POST superglobal contains input names, not input values. And your files, when using PHP, should be PHP files, not HTML files. And the names inside the square brackets need to be quoted. The META tag also needs to come after this PHP segment because the META tag requires the PHP variable definitions:
As a final note, because it appears that you wish index.php to be your default page, you should perhaps use:
Because what if, for whatever reason, neither "addteam" nor "finishedadding" have been clicked?
Code: Select all
<?php
if (isset($_POST['addteam'])) {
$page = 'addteam.php';
}
elseif (isset($_POST['finishadding'])) {
$page = 'index.php';
}
?>
<META HTTP-EQUIV="refresh" CONTENT="5;URL=<?php echo $page; ?>">
Code: Select all
if (isset($_POST['addteam'])) {
$page = 'addteam.php';
}
else {
$page = 'index.php';
}
Last edited by MichaelR on Wed Dec 23, 2009 4:14 pm, edited 2 times in total.
Re: different pages depending on button clicked
Code: Select all
<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>
Re: different pages depending on button clicked
thanks for trying to help me. i implemented the code you just put and get the following errors:
one button this error:
Notice: Use of undefined constant addteam - assumed 'addteam' in C:\wamp\www\addteam.php on line 12
Notice: Use of undefined constant html - assumed 'html' in C:\wamp\www\addteam.php on line 12
the other button this error:
Notice: Use of undefined constant index - assumed 'index' in C:\wamp\www\addteam.php on line 16
Notice: Use of undefined constant php - assumed 'php' in C:\wamp\www\addteam.php on line 16
then after 5 seconds get this error:
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.
any ideas?
thanks
one button this error:
Notice: Use of undefined constant addteam - assumed 'addteam' in C:\wamp\www\addteam.php on line 12
Notice: Use of undefined constant html - assumed 'html' in C:\wamp\www\addteam.php on line 12
the other button this error:
Notice: Use of undefined constant index - assumed 'index' in C:\wamp\www\addteam.php on line 16
Notice: Use of undefined constant php - assumed 'php' in C:\wamp\www\addteam.php on line 16
then after 5 seconds get this error:
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.
any ideas?
thanks
Re: different pages depending on button clicked
If you're getting those errors then I don't think you're doing what I suggested.
Edit: I take that back. I, for some reason, missed out the quotation marks.
Edit: I take that back. I, for some reason, missed out the quotation marks.
Re: different pages depending on button clicked
below is what my php currently looks like:
my index and addteam have no php in them thats why i have left them as html pages. is that okay?
iam still getting errors with this code
my index and addteam have no php in them thats why i have left them as html pages. is that okay?
iam still getting errors with this code
Code: Select all
<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 (isset($_POST['addteam'])) {
$page = addteam.html;
}
elseif (isset($_POST['finishadding'])) {
$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
Try this:
And change your files to PHP files. Just in case you choose to add PHP code to them.
Code: Select all
<html>
<head>
<?php
if (isset($_POST['addteam'])) {
$page = 'addteam.php';
}
else {
$page = 'index.php';
}
?>
<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>
<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.php">Home</a></li>
<li><a href="addteam.php">Create League/Cup</a></li>
<li><a href="statistics.php">View Statistics</a></li>
<li><a href="fixtures.php">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());
}
?>
<table>
<tr>
<td>Team Name: </td>
<td><?php echo $teamname; ?></td>
</tr>
<tr>
<td>Team Manager: </td>
<td><?php echo $teammanager; ?></td>
</tr>
</table>
<?php
print "You will be redirect in 5 seconds<br>";
mysql_close($conn);
?>
</div>
</div>
</div>
</div>
</body>
</html>Re: different pages depending on button clicked
i have changed them to php pages.
now after 5 seconds i get this error instead of directing me to the page i want:
Not Found
The requested URL /<br /><b>Notice</b>: Undefined variable: page in <b>C:\wamp\www\addteamprocess.php</b> on line <b>3</b><br /> was not found on this server.
thank you very much for your help. hoefully we are nearly there
now after 5 seconds i get this error instead of directing me to the page i want:
Not Found
The requested URL /<br /><b>Notice</b>: Undefined variable: page in <b>C:\wamp\www\addteamprocess.php</b> on line <b>3</b><br /> was not found on this server.
thank you very much for your help. hoefully we are nearly there
Re: different pages depending on button clicked
Have you used that code I offered in my last post?
Re: different pages depending on button clicked
sorry i thought i was using that code.
ive copied it in and it now working.... you legend.
what changes did you make? i have lost the original code to compare
thank you very much
ive copied it in and it now working.... you legend.
what changes did you make? i have lost the original code to compare
thank you very much
Re: different pages depending on button clicked
I mentioned a little earlier. The code which defines $page needs to run before your META tag, because the META tag uses the $page variable. Your other original errors were due to you using $_POST['Add New Team'] instead of $_POST['addteam'] (the bit which goes inside the $_POST suberglobal is the input name, not the input value).