1

I am new to coding and pardon me if it a silly thing I am missing. I have searched through the forum & did not find an answer that suits my need. I have 2 files: jobs.php & jobprocess.php

Jobs.php goes as

<?php session_start();
include('dbConnect.php');
$q1="abc";  
$q2="pqr";  
$q3="xyz";  
$opportunity=29;    
echo "Opportunity is". $opportunity;
?>

<html>
<head>
<div align="center">

<form method="post" method="post" action="jobprocess.php">


<input type="text" name="q1" placeholder="<?php echo $q1;?>"><br>
<input type="text" name="q2" placeholder="<?php echo $q2;?>"><br>
<input type="text" name="q3" placeholder="<?php echo $q3;?>"><br>
<input type="hidden" name="opportunity" value="<?php echo $opportunity;?>">


<ul class="actions">
<li><input type="submit" name="submit" value="I would like to join!! "></li>
</ul>                           
</form>                                 
</div>
</head>
<body>
</body>
</html>

jobprocess.php goes with the code

<?php session_start();
include('dbConnect.php');


$opportunity = $_GET['opportunity'];
echo "opportunity is " . $opportunity;
?>

Unfortunately, the above code is not defining value="29" for opportunity on 2nd page. Thanks in advance

1
  • your html is invalid Commented Sep 11, 2016 at 7:01

2 Answers 2

2

If you echo anything before the html tag it would effectively make the html invalid. Also, the head of the document MUST not have presentational html elements such as forms, divs etc

<?php
    session_start();
    include('dbConnect.php');
    $q1="abc";  
    $q2="pqr";  
    $q3="xyz";  
    $opportunity=29;    

?>

<html>
    <head>
        <title>must have a title</title>
    </head>
    <body>
        <?php
            echo "Opportunity is". $opportunity;
        ?>
        <div align="center">
            <form method="post" method="post" action="jobprocess.php">
                <input type="text" name="q1" placeholder="<?php echo $q1;?>"><br>
                <input type="text" name="q2" placeholder="<?php echo $q2;?>"><br>
                <input type="text" name="q3" placeholder="<?php echo $q3;?>"><br>
                <input type="hidden" name="opportunity" value="<?php echo $opportunity;?>">
                <ul class="actions">
                    <li><input type="submit" name="submit" value="I would like to join!! "></li>
                </ul>                           
            </form>                                 
        </div>
    </body>
</html>

And because the form is set to POST you should probably check and use the POSTed variable rather than a GET variable

<?php
    session_start();
    include('dbConnect.php');


    $opportunity = $_POST['opportunity'];
    echo "opportunity is " . $opportunity;
?>
Sign up to request clarification or add additional context in comments.

Comments

0

Surprisingly my answer that suggested using session variable instead of hidden form field was deleted?! I guess session variables are illegal now?

The answer was chosen for the best answer even.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.