Hamed Ap Hamed Ap - 1 month ago 6
PHP Question

How to use string from condition1 into condition2?

I have the following code:

<form action='' method='POST' id='form1'>
imdbcode : <input type='text' id='imdbcode' name='imdbcode' /><br/>
<input type='submit' name='submit' value='Get'/>
</form>
<?php
if(isset($_POST['submit'])){
.
.
.
$title = ... ;


echo "
<form action='' method='POST' id='form2'>
<input type='submit' name='Send' value='Send'/>
</form>";
}

if(isset($_POST['Send'])){

//I WANT TO USE $Title from condition1

} ?>


I want to use $title in second condition.

It prints $title in first condition! But doesn't print after closing condition!

How can I do that?

Answer

You can't.

Before you can enter the if(isset($_POST['Send'])) you need submit this one:

echo "
<form action='' method='POST' id='form2'>
<input type='submit' name='Send' value='Send'/>
</form>";

but the moment you submit this, the page will be refreshed and $_POST['submit'] will be deleted, without this variable the $title will not exist.

to fix this or make the $title value alive until the next refresh of the page. you must include the $title value along with the form2.

 echo "
 <form action='' method='POST' id='form2'>
 <input type='hidden' name='title' value="$title"/>
 <input type='submit' name='Send' value='Send'/>
 </form>";

and when the user send that form2 you can access the title by using

$_POST['title']