1

I have two php files which are doing some database work so i want to show them on single page so i created an html file and include both of the php files, this methods work well every time i use but not working now, please help to solve. Both file works good if i open them individually very well but including them in one html file is not working, including single php file is not working either, i am using single css file for both of php file and i tried even without css but they do not appear in main html.

            <html>
            <body >
                        <? php include 'user_addf.php'; ?>
                        <? php include 'user_remf.php'; ?>          
            </body>
            </html>

PHP file User_addf:

                <link href="users_forms.css" rel="stylesheet" type="text/css" />
                <div id="leftcolumn">
                    <form method="post" action="user_management_modf.php"><br/>
            <legend> Add Users </legend>
            <fieldset>
            Username:
            <input type="text" name="uname" id="" /><br /><br />
            Password :
            <input type="password" name="pass" id="" /><br /><br />
            <input type="submit" value="Add User" />
            </fieldset>
            </form>
                </div>


            <?php
                                // PHP code 
            ?>

2nd Php File user_remf:

                <link href="users_forms.css" rel="stylesheet" type="text/css" />

                <div id="rightcolumn">
                    <form method="post" action="user_remv.php"><br/>
            <legend> Remove Users </legend>
            <fieldset><br/>

            <?php
                        include'connect.php';
                        $q=mysql_query("SELECT username FROM user");

                        echo "<select name=uname_list''><option>Select a username</option>";
                        WHILE($row=mysql_fetch_array($q))
                         {
                            echo "<option name='uname_remove' value=$row[username]>".$row[username]."</option>"; 
                         }
                         echo "</select>";
            ?>

            <br/><br/><br/>
            <input type="submit" value="Delete User" />
            </fieldset>
            </form>
                </div>
12
  • What is the output your are getting ? Please make sure you save your main html file with an extension of php Commented Feb 9, 2015 at 3:33
  • I even tried to make the main file an php file but it still not working Commented Feb 9, 2015 at 3:34
  • white page, nothing appears ! Commented Feb 9, 2015 at 3:34
  • Do you have error reporting turned on? Commented Feb 9, 2015 at 3:37
  • ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); Do this at the top of your main php file Commented Feb 9, 2015 at 3:38

1 Answer 1

6

You cannot have a space between <? and php it must be <?php together.

Modify your code so that it is like this:

<?php include 'user_addf.php'; ?>
<?php include 'user_remf.php'; ?>

Having error reporting set would have given a parse/syntax error similar to this:

Parse error: syntax error, unexpected 'echo' (T_ECHO) in...

I used an "echo" statement in a quick test just to show you a possible message.

<? php 
echo "Hello world";

Then in comments you stated:

No they are different, fist its like, in main.html and include 'user_addf.php'; include 'user_remf.php'; in main.php

You can only execute PHP in .html files if you instructed Apache to treat .html files as PHP.

Either you do that, or rename the extension to be .php

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Error reporting should only be done in staging, and never production.

Sign up to request clarification or add additional context in comments.

2 Comments

@Mahesh Thank you. I feel it's important to point out details as to why code fails. Without an explanation, no one will learn anything. Cheers
Yes I agreed with you. keep it up

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.