PHP code problem can anyone help?

Cassie

New member
I need to Create a simple form with one text field for the user to enter their name (or any string).
When the submit button is pressed the output is displayed in a table.

Is this code right:

$strName = "Simon Stobart";
Â*echo "<table border='1' width='300'>";
echo "<tr align='center'>";
for ($intLetter=0;$intLetter<13;$intLetter++)
echo "<td>$intLetter</td>";
echo "</tr>";
echo "<tr>";
for ($intLetter=0;$intLetter<13;$intLetter++)
echo "<td align='center'>" . $strName{$intLetter} . "</td>";
echo "</tr>";
echo "</table>";

The code for my form:
<h2> Enter your Name: </h2>
<form action='<?php echo $_SERVER["PHP_SELF"]; ?>' method='post'>
<p>
<label for="strName">Name:</label>
<input type="text" name="strName" value='<?php echo $strName ?>' id='strName'/>
</p> <p>
<input type="submit" name="submit"/>
</p>
</form>

Do I need to add anything else?
 
1. Find this line:
$strName = "Simon Stobart";

And replace with this two lines:
$strName = $_POST['strName'];
$strCount = strlen($strName);

2. Find this line (placed twice: on line 4 and 8):
for ($intLetter=0;$intLetter<13;$intLetter++…

And replace each with this:
for ($intLetter = 0; $intLetter < $strCount; $intLetter++)
- - - - - - - - - - - - - - - -

I just added some functionality to be able to add whatever name in the form to process! Hope my suggestions will help you. Enjoy!
 
Back
Top