i have a table which is not showing, its showing the actual text. Here is the code:
<?php $form ="<form action='log.php' method='post'>
<table>
<tr>
<td>username</td>
<td>input type='text' name='user' /></td>
</tr>
<tr>
<td>password</td>
<td>input type='password' name='password' /></td>
</tr>
<tr>
<td></td>
<td>input type='submit' name='login' vaue='submit' /></td>
</tr>
</table>
</form>";
?>
It is not out-putting the table or the submit button or input area. Any suggestions why? Im using ubuntu with apache installed, normal tables, forms work and php is working but not when i try to output HTML using php its shows actual HTML and not its properties.
There was some html tag errors. Input tags html code was not proper. Replace with this and use echo() method to print $form variable's value.
<?php $form ="<form action='log.php' method='post'>
<table>
<tr>
<td>username</td>
<td><input type='text' name='user' /></td>
</tr>
<tr>
<td>password</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='login' value='submit' /></td>
</tr>
</table>
</form>";
echo $form;
?>
Hope this will solve your issue.
Your code looks about alright, just one thing you're missing and that's the following:
echo $form;
In order to print anything on your webpage, you use echo
followed by a value or variable.
use echo
like that :-
<?php
$form ="<form action='log.php' method='post'>
<table>
<tr>
<td>username</td>
<td><input type='text' name='user' /></td>
</tr>
<tr>
<td>password</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='login' value='submit' /></td>
</tr>
</table>
</form>";
echo $form;
?>
or change this input
to this <input
Remove echo and php tags itself.
<form action='log.php' method='post'>
<table>
<tr>
<td>username</td>
<td><input type='text' name='user' /></td>
</tr>
<tr>
<td>password</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='login' value='submit' /></td>
</tr>
</table>
</form>
My suggestion would be to do something like this:
<?php
function ShowHtml()
{
?>
<form action='log.php' method='post'>
<table>
<tr>
<td>username</td>
<td>
<input type='text' name='user' />
</td>
</tr>
<tr>
<td>password</td>
<td>
<input type='password' name='password' />
</td>
</tr>
<tr>
<td></td>
<td>
<input type='submit' name='login' value='submit' />
</td>
</tr>
</table>
</form>
<?php
}
?>
This removes the need to do an echo
or print
and also fixes your syntax errors(namely missing <
tags and the vaue
that should be value
).
Also in this you could have a function such as:
<?php
function ShowHtml($html)
{
if ($html != null || $html != '' || !empty($html)) # Just a check to make sure then html is set ;P
{
print $html; # could use echo instead, personal preference :)
# Could also add more validation to make sure the html tags themselves are valid and correct
return true;
}
return false;
}
?>
Or you could do (keeping the PHP surround):
<?php
$form = "<form action='log.php' method='post'>
<table>
<tr>
<td>username</td>
<td>
<input type='text' name='user' />
</td>
</tr>
<tr>
<td>password</td>
<td>
<input type='password' name='password' />
</td>
</tr>
<tr>
<td></td>
<td>
<input type='submit' name='login' value='submit' />
</td>
</tr>
</table>
</form>";
echo $form; # Or print, your choice :)
# Can also use the bracketed way of echo(...)
# or print(...) for an added layer of
# 'make sure I only print what I want to'
?>