Input text upload to MySQL DB I am uploading and selecting code from my MySQL DB and I have a feeling some of it could be written in a much shorter way but I don't know how. Can someone tell me if this is clean code or if it's too much?
&lt;?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

include 'config/connect.php';
$con = new mysqli(...$dbCredentials);

if (isset($_POST['add_execise'])) {
    # code...

    $create_exercise = $con-&gt;prepare(&quot;INSERT INTO exercises (exercise_name, difficulty) VALUES (?, ?)&quot;);
    $create_exercise-&gt;bind_param(&quot;ss&quot;, $_POST['exercise_creation'], $_POST['difficulty']);
    $create_exercise-&gt;execute();
}

if (isset($_POST['beginner'])) {
    # code...
    $get_exercises = $con-&gt;prepare(&quot;SELECT exercise_name, difficulty FROM exercises WHERE difficulty = ?&quot;);
    $get_exercises-&gt;bind_param(&quot;s&quot;, $_POST['beginner']);
    $get_exercises-&gt;execute();
    $get_exercises-&gt;store_result();
    $num_of_rows = $get_exercises-&gt;num_rows;
    $get_exercises-&gt;bind_result($exercise_selected, $difficulty);
}

if (isset($_POST['intermediate'])) {
    # code...
    $get_exercises = $con-&gt;prepare(&quot;SELECT exercise_name, difficulty FROM exercises WHERE difficulty = ?&quot;);
    $get_exercises-&gt;bind_param(&quot;s&quot;, $_POST['intermediate']);
    $get_exercises-&gt;execute();
    $get_exercises-&gt;store_result();
    $num_of_rows = $get_exercises-&gt;num_rows;
    $get_exercises-&gt;bind_result($exercise_selected, $difficulty);
}

if (isset($_POST['advanced'])) {
    # code...
    $get_exercises = $con-&gt;prepare(&quot;SELECT exercise_name, difficulty FROM exercises WHERE difficulty = ?&quot;);
    $get_exercises-&gt;bind_param(&quot;s&quot;, $_POST['advanced']);
    $get_exercises-&gt;execute();
    $get_exercises-&gt;store_result();
    $num_of_rows = $get_exercises-&gt;num_rows;
    $get_exercises-&gt;bind_result($exercise_selected, $difficulty);
}
?&gt;

&lt;form action=&quot;create.php&quot; method=&quot;POST&quot;&gt;
    &lt;input type=&quot;text&quot; name=&quot;exercise_creation&quot; placeholder=&quot;exercise&quot;&gt;
    &lt;input type=&quot;text&quot; name=&quot;difficulty&quot; placeholder=&quot;difficulty&quot;&gt;
    &lt;input type=&quot;submit&quot; name=&quot;add_execise&quot;&gt;
&lt;/form&gt;

&lt;p&gt;Choose level of difficulty:&lt;/p&gt; &amp;nbsp;&amp;nbsp; 
&lt;form action=&quot;create.php&quot; method=&quot;POST&quot;&gt;

    &lt;button id=&quot;beginner&quot; name=&quot;beginner&quot; value=&quot;beginner&quot;&gt;Beginner&lt;/button&gt;&lt;br&gt;&lt;br&gt;

    &lt;button id=&quot;intermediate&quot; name=&quot;intermediate&quot; value=&quot;intermediate&quot;&gt;Intermediate&lt;/button&gt;&lt;br&gt;&lt;br&gt;

    &lt;button id=&quot;advanced&quot; name=&quot;advanced&quot; value=&quot;advanced&quot;&gt;Advanced&lt;/button&gt;
&lt;/form&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;

&lt;?php 


    while ($get_exercises-&gt;fetch()) {
        # code...

        echo $exercise_selected . &quot;&lt;br&gt;&quot;;
    }

?&gt;
Can someone tell me if this is clean code...

The code is somewhat easy to read (e.g. it appears to somewhat align with the recommendations of PSR-12. It is also great that parameters are bound to the queries so SQL injection should be less likely to occur.

...or if it's too much?

The mixing of PHP within HTML is not great. It is recommended to have the PHP fetch data and then within the HTML just output any data that might have been retrieved.
There are quite a few duplicate lines in these three blocks:

if (isset($_POST['beginner'])) {
    # code...
    $get_exercises = $con-&gt;prepare(&quot;SELECT exercise_name, difficulty FROM exercises WHERE difficulty = ?&quot;);
    $get_exercises-&gt;bind_param(&quot;s&quot;, $_POST['beginner']);
    $get_exercises-&gt;execute();
    $get_exercises-&gt;store_result();
    $num_of_rows = $get_exercises-&gt;num_rows;
    $get_exercises-&gt;bind_result($exercise_selected, $difficulty);
}

if (isset($_POST['intermediate'])) {
    # code...
    $get_exercises = $con-&gt;prepare(&quot;SELECT exercise_name, difficulty FROM exercises WHERE difficulty = ?&quot;);
    $get_exercises-&gt;bind_param(&quot;s&quot;, $_POST['intermediate']);
    $get_exercises-&gt;execute();
    $get_exercises-&gt;store_result();
    $num_of_rows = $get_exercises-&gt;num_rows;
    $get_exercises-&gt;bind_result($exercise_selected, $difficulty);
}

if (isset($_POST['advanced'])) {
    # code...
    $get_exercises = $con-&gt;prepare(&quot;SELECT exercise_name, difficulty FROM exercises WHERE difficulty = ?&quot;);
    $get_exercises-&gt;bind_param(&quot;s&quot;, $_POST['advanced']);
    $get_exercises-&gt;execute();
    $get_exercises-&gt;store_result();
    $num_of_rows = $get_exercises-&gt;num_rows;
    $get_exercises-&gt;bind_result($exercise_selected, $difficulty);
}


It appears that only two of each eight lines in each block changes - i.e. the if condition and the second parameter passed to $get_exercises-&gt;bind_param().
A commonly accepted principle is the Don't Repeat Yourself. principle. The common lines could be abstracted to a function, or even a simple check for common values:
Instead of setting the name attribute uniquely on each button

&lt;button id=&quot;beginner&quot; name=&quot;beginner&quot; value=&quot;beginner&quot;&gt;Beginner&lt;/button&gt;&lt;br&gt;&lt;br&gt;


Set the name on all three the same - e.g. name=“difficulty”. That can make the query logic much simpler:
//initialize to avoid undefined variables if POST not set
$exercise_selected = $difficulty = null;
if (isset($_POST['difficulty']) {
    $get_exercises = $con-&gt;prepare(&quot;SELECT exercise_name, difficulty FROM exercises WHERE difficulty = ?&quot;);
    $get_exercises-&gt;bind_param(&quot;s&quot;, $_POST['difficulty']);
    $get_exercises-&gt;execute();
    $get_exercises-&gt;store_result();
    $num_of_rows = $get_exercises-&gt;num_rows;
    $get_exercises-&gt;bind_result($exercise_selected, $difficulty);
}