Page 2 of 2

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 3:29 pm
by daedalus__
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.

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 3:40 pm
by ryan1987
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

Code: Select all

$page = "";
to initialize it and it still didnt work

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 3:55 pm
by manohoo
Sorry daedalus. it's my first time day in this forum and I did not know the protocol.

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 3:59 pm
by MichaelR
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:

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; ?>">
 
As a final note, because it appears that you wish index.php to be your default page, you should perhaps use:

Code: Select all

 
  if (isset($_POST['addteam'])) {
    $page = 'addteam.php';
  }
 
  else {
    $page = 'index.php';
  }
 
Because what if, for whatever reason, neither "addteam" nor "finishedadding" have been clicked?

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 4:04 pm
by manohoo

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>
 
The above will not work because you can't call the variable $page, since it has not been defined yet.

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 4:10 pm
by ryan1987
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

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 4:12 pm
by MichaelR
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.

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 4:17 pm
by ryan1987
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

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

Posted: Wed Dec 23, 2009 4:20 pm
by MichaelR
Try this:

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>
And change your files to PHP files. Just in case you choose to add PHP code to them.

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 4:26 pm
by ryan1987
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

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 4:42 pm
by MichaelR
Have you used that code I offered in my last post?

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 4:55 pm
by ryan1987
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

Re: different pages depending on button clicked

Posted: Wed Dec 23, 2009 5:00 pm
by MichaelR
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).