I have a section in my PHP page containing this bit of code:

echo '<div style="float:left;"><h3><strong>Edit User Account</strong></h3>
                                Date Registered: ' . $db_regdate . '<br>
                                User Type: ' . $usertype . '<br><br>
                            <form class="right_aligned" id="form1" name="form1" method="post" action="">
          				      <label>First Name*</label>
                				  <input name="firstname" type="text" id="firstname" value="' . $db_firstname . '"/>
                        <label>Last Name*</label>
                				  <input name="lastname" type="text" id="lastname" value="' . $db_lastname . '" />
                			     <label>Email Address*</label>
                				  <input name="email" type="text" id="email" value="' . $db_email . '" size="32" />                 			  
                				<label>New Password</label>
                                    <input name="password" type="password" id="password" size="10" />
                			    <label>Verify Password</label>
                			      <input name="verifypass" type="password" id="verifypass" size="10" />
        	                   <label>User Type </label>
                                  <select name="usertype" class="header" id="usertype">
                                    <option>Admin</option>
                                    <option>Staff</option>
                                    <option selected="selected">Client</option>
                                  </select>
                				<label></label>
                				  <input type="submit" name="submit_edit" id="submit_edit" value="save" />
                            </form>';

As you can see, I have concatenated (or whatever the appropriate term is) some essential variables within the form. This is basically an edit form so the variables basically load content from the database and display is on the form as 'initial values'.

What I'm trying to do it relocate the form to a file named edit_user.html. HOWEVER, if I try to use PHP include to include the form from an external file I do not get the same result. Instead of displaying the content of the variables, it does not parse the variables as a variable and instead it just displays:

' . $variable . ' in each field.

Where am I going wrong?

I am using this instead of the echo statement:

include('modules/forms/edit_user.html');

If I try to echo the include, I get the same result :(

Recommended Answers

All 4 Replies

i think the problem is you've saved your code in an html file.
As it's php code, you need to save it as a php file not html.

include('modules/forms/edit_user.php');

Thanks for your reply, but it still seems to bring the same problem :(

Thanks for your reply, but it still seems to bring the same problem :(

This worked for me just now on a test, you will need to change the sql details to suit your needs but...
in the main php and sql page

$sql  = "select * from users where username='emhmk1'";

$q = mysql_query($sql);
$r = mysql_fetch_array($q);
include ('name.html');

bear with me wth the code, it's very cruedly written!!
then in the edit html page (i called mine name.html)

<form action="" name="form" method="post">
Name:<br />
<input type="text" name="name" value="<?php echo  $r['username'];?>" />
</form>

That echo's out my username in the value of the input box.

Hope it helps

commented: Thanks. +1

This worked for me just now on a test, you will need to change the sql details to suit your needs but...
in the main php and sql page

$sql  = "select * from users where username='emhmk1'";

$q = mysql_query($sql);
$r = mysql_fetch_array($q);
include ('name.html');

bear with me wth the code, it's very cruedly written!!
then in the edit html page (i called mine name.html)

<form action="" name="form" method="post">
Name:<br />
<input type="text" name="name" value="<?php echo  $r['username'];?>" />
</form>

That echo's out my username in the value of the input box.

Hope it helps

Ahh, that makes more sense. Thanks a lot, I really appreciate it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.