Classes. So a lot of logic is spread out throughout the files here, so it's tough to understand what everything is doing.
I'll make an example of createtemplate.
./lib/madlib.php:
<?
public class Madlib()
{
public __construct()
{
}
public GenerateWords($number_of_words)
{
$output = [];
if($number_of_words == 0 || $number_of_words > 20)
{
throw new Exception("hey too many words");
}
for($i = 0; $i < $number_of_words; $i++)
{
$output[] = chr(rand(65,90));
}
return $output;
}
}
?>
./create_template.php
<?
require('./lib/madlib.php');
$madlib = new Madlib();
try
{
$words = $madlib->GenerateWords($_POST['howmanywords']);
}
catch(Exception $e)
{
// do something about errors.
}
?>
<!DOCTYPE html>
<html>
<style>
body
{
background-color:#6699ff;
}
</style>
<body>
You have selected this many words: <?= $_POST['howmanywords'] ?>
<br/>
<form method="post" action="checkphrase.php">
<?
foreach($words AS $i => $word)
{
echo "\n <br>";
echo $word;
echo " : <textarea name=\"$word"."_"."$i\"></textarea>";
echo "\n <br>";
echo "\n <br>";
}
?>
Fill in the phrase!
<br/><br/>
<input type="submit" value="Submit Phrase."/>
</form>
</form>
<br>
<br>
<a href="dumpdb.php">Dump db</a>
</body>
</html>
This gets better if you have a controller and view where you can separate out some of the logic a bit more, but without getting into that the above is OK.
So you'd want to expand on the madlibs class with other logic from pages, and reference that. Generate the dictionary/pspell through there, etc. the constructor method is a magic function which runs when you instantiate the class so if there's setup (i.e. generating the pspell class), it's good to do there. It's optional too so if you don't end up putting anything there you can remove.
Style and shit
I'm not doing to go too much into this, but using an existing framework for styling makes it easier to generate something quick and something that looks good. https://getbootstrap.com/ as example, basically look up CSS frameworks for examples.
PHP framework: lookup and try to use something like Laravel, CodeIgniter, or Symfony to build your php app on, you can get some of that templating/MVC separation I was talking about in #3.
Consider using PDO instead of mysqli. mysqli is fine but PDO is compatible with other DBs, and you're not doing anything mysql specific here so it's a good win to have the ability to not care about which DB you're using.
not sure if this is applicable, but i see dumpdb.php and want to make sure this isn't the only way you're able to interrogate your db. you can use a client to make administration a bit easier, like mysql workbench or https://dbeaver.io/, not sure what else is around but a decent client that allows you to view/query db directly is easier than creating php code to do that shit
no need for $i = ''; in createtemplate.php, at least when you're putting work in a class/function. Even as-is you don't need it.
initial feedback, might have more to go as I dig deeper.
I'll make an example of createtemplate.
./lib/madlib.php:
./create_template.php
Style and shit
PHP framework: lookup and try to use something like Laravel, CodeIgniter, or Symfony to build your php app on, you can get some of that templating/MVC separation I was talking about in #3.
Consider using PDO instead of mysqli. mysqli is fine but PDO is compatible with other DBs, and you're not doing anything mysql specific here so it's a good win to have the ability to not care about which DB you're using.
not sure if this is applicable, but i see dumpdb.php and want to make sure this isn't the only way you're able to interrogate your db. you can use a client to make administration a bit easier, like mysql workbench or https://dbeaver.io/, not sure what else is around but a decent client that allows you to view/query db directly is easier than creating php code to do that shit
no need for
$i = '';
in createtemplate.php, at least when you're putting work in a class/function. Even as-is you don't need it.