Hi all this should be an easy one,

Trying to move an input from text box1 to text box2 and return back to page1.

page 1 reads,

<HTML><HEAD><TITLE>php scenario move text </TITLE><META content="text/html; charset=utf-8" http-equiv=Content-Type><META name=GENERATOR content="MSHTML 9.00.8112.16457"><STYLE type=text/css>BODY {
    FONT-FAMILY: verdana, arial, sans-serif
}</STYLE></HEAD><BODY><P>
</P><P><FORM method=post action=2.php>
<TABLE border=1 cellSpacing=2 cellPadding=1 width=100>
<TBODY><TR><TD valign=center align=center>
<INPUT name=box1 value="Text Field"></TD></TR><TR><TD valign=center align=center>
<INPUT value="Submit Query" type=submit></TD></TR><TR><TD valign=center align=center>
<INPUT name=box2 value="Text Field"></TD></TR><TR><TD valign=center align=center>
</TD></TR></TBODY></TABLE><BR></FORM>
</P></BODY></HTML>

2.php reads

<?php

  box2 = text_box1 ;
   1.php;

   ?>
<HTML><HEAD>
<META name=GENERATOR content="MSHTML 9.00.8112.16457"></HEAD>
<BODY></BODY></HTML>

I know this is basic however it may help someone.

I may be being dense here, but there is no sense in this post.
The first code is extremely difficult to read, because it has no indentation, like trying to read a book with no punctuation, and the 2nd 'script' is complete non-sense.
Is there a question here?

first change the code:
of your html and place the code below before your <HTML> opening

<?php
//initialize variables
$pass_text1;
$pass_text2;
//if text box 1 only
if(isset($_POST['box1'])&&(isnull($_POST['box2']))){
$pass_text2=$_POST['box1'];
$pass_text1='';
}
//if text box 2 only
else if(isset($_POST['box2'])&&(isnull($_POST['box1']))){
$pass_text1=$_POST['box2'];
$pass_text2='';
}
//if both has value
else if(isset($_POST['box1'])&&(isset($_POST['box2']))){
$pass_text2=$_POST['box1'];
$pass_text1=$_POST['box2'];
}
//if both none
else{
$pass_text1='';
$pass_text2='';
}
?>

in your html form tag. edit the form tag and replace into this
`<form action="<?php htmlspecialchars($_SERVER['PHP_SELF']);?>" method=post>

that way you will not loop back from one page back to the previous page because the page will load it self with the PHP loaded values already

for getting the value after an input has done and loops back as the form submits...
replace the text box tag to:
<input type='textbox' name='box1' value='<?php echo $pass_text1;?>'>
and your text box 2
<input type='textbox' name='box2' value='<?php echo $pass_text2;?>'>

see what happens after you follow this carefully. If you like it please endorse me :)

Member Avatar for diafol

From where did you get this code? It doesn't resemble any php that I know of.
Have a look at some php tutorials. Also the HTML is horrible (no offence) - was it generated automatically?

And, what exactly is your question?

Yes page 1 code was generated automatically , by placing a table on the work space and then adding text boxes to it and a submit button then I went to the source view and copy n pastted the code from there to here.

page 2 is me trying to code in Notepad with bits.

The idea i am trying to do is make simple lego type block of code that works so later on I can look back an take all the bricks and try to build a ie yellow bricks take text and moves it , blue bricks takes text and adds it to another, red bricks takes a pic. ect.

thanks for helpping.

<?php
    //initialize variables
    $pass_text1;
    $pass_text2;
    //if text box 1 only
    if(isset($_POST['box1'])&&(isnull($_POST['box2']))){
    $pass_text2=$_POST['box1'];
    $pass_text1='';
    }
    //if text box 2 only
    else if(isset($_POST['box2'])&&(isnull($_POST['box1']))){
    $pass_text1=$_POST['box2'];
    $pass_text2='';
    }
    //if both has value
    else if(isset($_POST['box1'])&&(isset($_POST['box2']))){
    $pass_text2=$_POST['box1'];
    $pass_text1=$_POST['box2'];
    }
    //if both none
    else{
    $pass_text1='';
    $pass_text2='';
    }
    ?>


<HTML><HEAD><TITLE>php yellow brick</TITLE><META content="text/html; charset=utf-8" http-equiv=Content-Type><META name=GENERATOR content="MSHTML 9.00.8112.16457"><STYLE type=text/css>BODY {
    FONT-FAMILY: verdana, arial, sans-serif
}</STYLE></HEAD><BODY><P>
</P><P><form action="<?php htmlspecialchars($_SERVER['PHP_SELF']);?>" method=post>
<TABLE border=1 cellSpacing=2 cellPadding=1 width=100>
<TBODY><TR><TD valign=center align=center>
<input type='textbox' name='box1' value='<?php echo $pass_text1;?>'></TD></TR><TR><TD valign=center align=center>
<INPUT value="Submit Query" type=submit></TD></TR><TR><TD valign=center align=center>
<input type='textbox' name='box2' value='<?php echo $pass_text2;?>'></TD></TR><TR><TD valign=center align=center>
</TD></TR></TBODY></TABLE><BR></FORM>
</P></BODY></HTML>

this gives the error

Fatal error: Call to undefined function isnull() in /home/a5584711/public_html/1.php on line 6

however I have learnt how to post back to the same page with-out having to make another, thank youmasterjiraya .

The correct function is is_null().

Thanks EvolutionFallen ,

if (isset($_POST['box1']) && is_null($_POST['box2']))

From the manual: "isset — Determine if a variable is set and is not NULL". So you can safely remove the is_null from the if as it will have no additional effect:

if (isset($_POST['box1']))

i'm sorry folks I mispelled my isnull that should be is_null hahaha, my stupidity. I'm so sorry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.