Log in

View Full Version : How to generate a users choice table



sonth321
04-26-2016, 01:35 PM
I am attempting to create a table that consists of 2 forms where the first form gets info from the second. so i have table1 and table 2. I want to make it to be users choice . a user picks the number of rows and columns(I went up to 7 rows and columns in dropbox) and color from a drop down box and whatever they pick it generates. My problem is when I select something instead of showing me a table row and columns with the colors its showing me 1111 can anyone suggest something? Maybe my logic is wrong please help.

?php
$color= substr(filter_input(INPUT_GET,'color',FILTER_SANITIZE_NUMBER_INT),0,10);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Table">
<meta name="description" content="table Creator">
<link rel="stylesheet" type="text/css" href="style.css">
<style>
tr:nth-child(even) {
background-color:#000000;
color:#000000;
<?php
echo $color
?>;
}
table, th, td {
border: 1px solid #000000; ;
padding: 10px;
}
table {
border-collapse: collapse;
}
</style>

<title>table</title>


</head>

<body>
<header>
<h1> Projects</h1>
</header>


<nav>

</nav>

<section>

<h2> Table Creator</h2>



<?php
$rows= substr(filter_input(INPUT_GET,'rows',FILTER_SANITIZE_NUMBER_INT),0,3);
$cols= substr(filter_input(INPUT_GET,'cols',FILTER_SANITIZE_NUMBER_INT),0,3);


echo "<Table>";


for ($x=1; $x<=$rows; $x++)
{

echo "<tr>";
for ($y=1; $y<=$cols; $y++)

echo "<td>$rows $x $cols $y</td>";
}

{
echo "<tr>";
}

echo "</Table>";




?>


</section>

<footer>

</footer>

<p></p>

</body>
</html>

jscheuer1
04-26-2016, 02:08 PM
Works OK here, the color logic seems flawed. I called mine user_choice_h.php and used this url:

user_choice_h.php?color=ff0012&rows=3&cols=4

Now the trouble with color is at least twofold. One, it's filtering for an integer, so ff and other higher hex digits get stripped. Even if the hex value made it through, the way it is written out in the code in the style section doesn't result in a valid color declaration.

The rest seemed fine (click image to see result).

5889

styxlawyer
04-26-2016, 03:58 PM
The PHP function ctype_xdigit($string) will check that every character in $string is an hex digit and return a boolean TRUE or FALSE. It doesn't alter the string in any way.

That might be useful.