php - im lost with validating my code -
can me validate codes? user should able input numeric or integer only. have tried using ctype_digit isnumeric , more else , because didnt quite understand on how use nothing successful
<?php $table = ''; if ($_post) { $table .= '<table border="4">'; ($i = 0; $i < $_post['rows']; $i++) { $table .= '<tr>'; ($j = 0; $j < $_post['column']; $j++) { $table .= '<td width="100"> </td>'; } $table .= '</tr>'; } $table .= '</table>'; } ?> <?php echo "a table "; echo $_post['rows']; echo " row(s) , "; echo $_post['column']; echo " column(s) " ;?> <?php echo $table; ?> <form action="" method="post"> <table border="0" width="729"> <tr> <td width="39"><label>rows :</label></td> <td width="144"><input type="text" name="rows"></td> <td width="51" ><label>column :</label></td> <td width="352" ><input type="text" name="column"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="create table"></td> </tr> </table> </form> <br /> <br />
by way form should validate using php . thank in advance !!
thank guys , sorry inconvenience complete code .
<?php $table = ''; $row= $_post['rows']; $column=$_post['column']; if (isset ($_post['submit'])){ if($row=="") $error= "error : please fill out row"; else if($column=="") $error= "error : please fill out column"; elseif(is_numeric($row)==false) $error= "error number only"; elseif(is_numeric($column)==false) $error= "error number only"; else { $table .= '<table border="4">'; ($i = 0; $i < $_post['rows']; $i++) { $table .= '<tr>'; ($j = 0; $j < $_post['column']; $j++) { $table .= '<td width="100"> </td>'; } $table .= '</tr>'; } $table .= '</table>'; echo "a table "; echo $row; echo " row(s) , "; echo $column; echo " column(s) " ; echo $table; } } ?> <?php if (isset($error)) { echo "<font color='ff0000'><center><b>". $error . "</b></center></font>"; } ?> <form action="" method="post" > <table border="0" width="729"> <tr> <td width="39"><label>rows :</label></td> <td width="144"><input type="text" name="rows"></td> <td width="51" ><label>column :</label></td> <td width="352" ><input type="text" name="column"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="create table"></td> </tr> </table> </form> <br /> <br />
Comments
Post a Comment