php - trying to write a script that redirects to another page using data that was put in to a form -


i trying write script redirect page using data put in form. here script have now.

<form id="form1" name="form1" method="post" action="redirect.php?=sendtext"> <p> <label for="phone">phone number:&nbsp;</label> <input type="text" name="phone" id="phone" /> </p> <p> <input name="submit" type="button" value="text coupon" /> </p> </form> <?php  $phone == $_get['phone'];  if($_get['form1'] == 'sendtext'){     header("location: www.head1stapparel.com/" . $phone . "");     die(); }  ?> 

it doesn't seem work. can give me 1 please help? thanks!

here entire page.

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head>  <body>  <?php $phone = $_post['phone'];  if($_get['sendtext'] == 1){ header('location: http://www.head1stapparel.com'); die(); } else {  ?> <form id="form1" name="form1" method="post" action="redirect.php?sendtext=1"> <p> <label for="phone">phone number:&nbsp;</label> <input type="text" name="phone" id="phone" /> </p> <p> <input name="submit" type="submit" value="text coupon" /> </p> </form> <? } ?> </body> </html> 

the reason why code isn't working, because have output before header. masking fact php throwing error , in not displaying it.

  • using error reporting confirm this.
  • consult footnotes this.

you need place php above html form.

sidenote #1: don't know want achieve here, if plan on echoing under header(), won't able to; considered output.

even simple cookie, byte order mark, space before opening php tag; nothing.

so, here rewrite php on top, followed html form.

  • what choose hereon in, you.

sidenote #2: fyi, forms not bear name attribute, yet did leave in form tag.

<?php $phone = $_post['phone'];  if($_get['sendtext'] == 1){ header('location: http://www.head1stapparel.com'); die(); } else {  ?>  <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head>  <body>  <form id="form1" name="form1" method="post" action="redirect.php?sendtext=1"> <p> <label for="phone">phone number:&nbsp;</label> <input type="text" name="phone" id="phone" /> </p> <p> <input name="submit" type="submit" value="text coupon" /> </p> </form> <? } ?> </body> </html> 

foonotes:

add error reporting top of file(s) find errors.

<?php  error_reporting(e_all); ini_set('display_errors', 1);  // rest of code 

sidenote: error reporting should done in staging, , never production.


using present formatted code:

in order use presently formatted code, there may quick fix work @ times can fail, use ob_start(); @ top of code, followed rest.

for example:

<?php  ob_start(); ?>  <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">  ... rest of code 
  • as said, not work, can try it.

  • as header("location: www.head1stapparel.com/" . $phone . ""); well, can incorporate in code somehow. don't know ultimate goal is.

  • location: www.head1stapparel.com/ that, should have http:// @ beginning.

  • header("location: http://www.head1stapparel.com/" . $phone . "");

  • consult manual: http://php.net/manual/en/function.header.php


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -