0

Hi,

How to pass an array to a form which is above the part where the array is created

I have a php script with html in it. The page is divided into blocks using div tags. There is a form in a div tag which is at the top which needs id generated by a sql query in a div tag below it. Changing the positions of div tag will change the entire look of the page.

Edited by harshm027

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by harshm027
0

Put the php block that generates required data at the top or before the form div (this won't change the appearenca of the page).

0
<?php

?>
<html>

<body>
    <div id="main_container">
        <div id="column1">
            <form>
                //requires ids
            </form>
        </div>
        <div id="column2">
            <?php
                //gets input from a form submitted in another page
                //Compares value in the database
                while ($row = mysql_fetch_array($result))
                {
                    echo "output";
                    array1[] = //store each id in an array
                }

            ?>
        </div>
    </div>
</body>
</html>
0

If I put the php block above then the result appears on a blank page.

I want the page to appear in the middle with other menus and columns i.e i want the css to apply to the result

0

I tried putting the php block on top and the part that generates and displays the result in the div tag.
Now result appear according to the css.

But there is an If condition that echo's 'Please enter something' if all form fields are emty.
This message is coming on a separate blank page. I would like it to come on the same page of the form or in the div tag. How do I manage that?

0

Initialize a variable that will hold the error message:

$error_msg = '';

On the beginning it will be an empty string. When checking form fields and if all are empty (or invalid values) assign an error message to the $error_msg variable. At hte end of the script (or anywhere else) place a condition that will display a div tand the contents of the $error_msg.

if($error_msg != '') {
    echo "<div class="error-msg">$error_msg</div>";
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.