My script below uses 2 usergiven variabels to create a table and echo this to the browser.
But what I really tried to make was a table with input fields (depending on the given cols/rows) so the user of this coming CMS system(This was the hardest part for me) just have to fill in the fields. and their given data will be written to the browser.
How can I change my code, maybe by using 2 pages.php
where I first:
1st receive the var input from the user.
2 rd collect the data in my mysql database, like I did with the other info.
3rd display this filled in table form to the user, so my site will have a consistent style. (css)
Thanks in advance.
<?php $var1=$_POST['var1'];
$var2= $_POST['var2'];
function valid_var1($str) {
return (ereg ('[0-9]{0,}$', $str));
}
function valid_var2($str) {
return (ereg ('[0-9]{0,}$', $str));
}
if ($verzendbutton != "verzenden" || !valid_var1($var1) || !valid_var2($var2)) {
echo "<form action=\"$PHP_SELF\" method=\"post\">";
?>
<input type="text" name="var1" value="<?php echo $var1?>" size="10" maxlength="10">
<php if ($verzendbutton && !valid_var1($var1)) {
echo "<span class=\"fout\">Vul hier het aantal rijen in</span>";
}
?>
Kolommen: <input type="text" name="var2" value="<?php echo $var2 ?>" size="10" maxlength="10">
<td colspan="2"><?php if ($verzendbutton && !valid_var2($var2)) {
echo "<span class=\"fout\">Vul hier het aantal rijen in</span>";
}
?></td>
</tr>
<tr><td>
<input type="submit" value="verzenden" name="verzendbutton">
<input type="reset" value="wissen" name="wissen">
</td></tr></table>
</form>
<?php
} else { // in alle andere gevallen (dus formulier verzonden)
$cols = "<td> Do I have to put a input field here?</td>";
$rows = "<tr>";
$rowsend = "</tr>";
echo '<table>';
for ( $rij =0; $rij < $var1; $rij++ )
{
echo "$rows";
for ($col=0; $col < $var2; $col++ )
{
echo "$cols";
}
echo "$rowsend";
}
echo '</table>';
}
?>