Jump to content

php created Button to refer to a new page


JayDude

Recommended Posts

I am a newby using php as the backbone for my web design, with a help from phpFreeks, I have come along way in a short time.

 

Below is a short script of two buttons created with php, how can I use the buttons to link to a new web page (similar to using "href" in html)?

I would like to use the php created buttons to keep the general look and feel to my site the same through.

 

In advance, thank you for the support...

 

This is the part in my normal page that shows the buttons:

 

echo "<form action='processButtonsDdr.php' method='POST'>

<input type='submit' name='display_button'

value='homepage' />

<input type='submit' name='display_button'

value='new entry' />

 

This is a snippet from my two button process page:

 

<?php

if($_POST['display_button'] == "home page")

{

????????????????? // what do I enter in this area to point the button to another webpage?

}

else

{

?????????????????

}

?>

I have tried what you stated, but not one of the buttons point me in the right direction.

 

Error Message: Website not found error:404

 

Here are the two headers:

 

header("Location: ../home/test.htm");  //from public_html/home/test.htm

 

and

 

header("Location: addDdr.php");  //in the same folder as process file

still not working, here is the complete script from the process page: (error:404 web page not found)

 

<?php

if($_POST['display_button'] == "home page")

{

header("Location: http://www.ad181.co.za/home/test.htm");    // with the www

}

else

{

header("Location: http://ad181.co.za/insert/addDdr.php");  // without the www

}

?>

That just a path issue relative to the page processing the code.  Understand also, you'll to have these header("location:"); lines above anything that might be sent to the browser and it should be followed by exit;

<?php
   if($_POST['display_button'] == "home page")
   {
      header("Location: test.htm"); 
exit;
   }
   else
   {
      header("Location: addDdr.php");
exit;
   }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
etc.

I just dont know what I'm doing wrong here, even copied your script snipped into the page, even deleted all non php script, so its only looking like the snippet you gave me, to no avail...

 

Is there a way not to use a process page, but rather do it within the original form?

Make sure form values match.  Looks like you have "homepage" in your form and "home page" in processing.  I would also use isset() so values not posted don't throw errors.  Btw, method post in the form should be lower case to validate but should work regardless.  So instead of using and else statement I would just use an if statement for each line and wrap it all in an isset() statement.  You could also use a switch if want to look into that, but for now let's just get things working.

<?php
if (isset($_POST['display_button'])){
if($_POST['display_button'] == "homepage")
{
   header("Location: test.htm"); 
exit;
}
if($_POST['display_button'] == "new entry")
{
   header("Location: addDdr.php");
exit;
} 
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.