Jump to content

PHP code question for changing pages


fuzzylr

Recommended Posts

Expectation of code: I would like it to take the number the customer selects and based on that number load a different page. So you load into index.php The options are 1 - 4. I am receiving the information into Variables. However, it's not changing the page. Here is the code for it to change the page.

header('Location: driven' + $num + '.html');}

Also is there a better way of breaking out of php code?

<?phpif(isset($_POST['submit'])){echo "Submit button has been pressed"; ?><br /><?phpecho $num; ?><br /><?phpif ($num < 1){  $error="Invalid option";  echo $error;}else{  header('Location: driven' + $num + '.html');}}?>

Notice all the

<?php ?>

??

Link to comment
Share on other sites

There is no need for all of the <?php opening and closing, you can echo out HTML. You also had an extra bracket after your header()

<?phpif(isset($_POST['submit'])){echo "Submit button has been pressed <br />";echo $num . "<br />";if ($num < 1){  $error="Invalid option";  echo $error;}else{  //header('Location: driven' + $num + '.html');}  looks like an extra } on thereheader('Location: driven' + $num + '.html');}?>

Link to comment
Share on other sites

In PHP you use a dot to join strings, a plus is for arithmetic addition.
Thank you. This worked very well.
header('Location: driven' . $num . '.html');}

Link to comment
Share on other sites

sorry, that was my bad. I gave a bad example herehttp://w3schools.invisionzone.com/index.php?showtopic=42241&st=0&p=234445entry234445 (I've since changed it to ., from +)

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...