1,105,406 Community Members

Basic Starter Question

Member Avatar
Kniggles
Junior Poster
105 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
TonyG_cyprus
Posting Whiz
329 posts since Dec 2009
Reputation Points: 36 [?]
Q&As Helped to Solve: 47 [?]
Skill Endorsements: 2 [?]
 
0
 

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?

Member Avatar
masterjiraya
Posting Whiz
327 posts since Jul 2008
Reputation Points: -3 [?]
Q&As Helped to Solve: 32 [?]
Skill Endorsements: 4 [?]
 
0
 

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
diafol
Where are my eyes?
12,985 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

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?

Member Avatar
Webville312
Posting Whiz
367 posts since Feb 2012
Reputation Points: 14 [?]
Q&As Helped to Solve: 34 [?]
Skill Endorsements: 0 [?]
 
0
 

And, what exactly is your question?

Member Avatar
Kniggles
Junior Poster
105 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
Kniggles
Junior Poster
105 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
<?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 .

Member Avatar
EvolutionFallen
Posting Pro
504 posts since Aug 2009
Reputation Points: 107 [?]
Q&As Helped to Solve: 108 [?]
Skill Endorsements: 8 [?]
 
1
 

The correct function is is_null().

Member Avatar
Kniggles
Junior Poster
105 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks EvolutionFallen ,

Question Answered as of 1 Year Ago by diafol, masterjiraya, EvolutionFallen and 2 others
Member Avatar
pritaeas
mod_pritaeas
11,316 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 
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']))
Member Avatar
masterjiraya
Posting Whiz
327 posts since Jul 2008
Reputation Points: -3 [?]
Q&As Helped to Solve: 32 [?]
Skill Endorsements: 4 [?]
 
0
 

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

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: