Using form variables within the same page

Good day,

I have found many information about how to pass form variables from onbe webpago to another, but how can I use these variables within the same webpage where the for is?

Let’s say I have a form and two variables:
<form action=“target_webpage” method=“post”>
<p>
Nombre del alumno: <input type=“text” class=“lists_input” name=“Student_Name” /><br>
</p>
<p>
Nombre del apoderado: <input type=“text” class=“lists_input” name=“Parent_Name” /><br>
</p>
</form>

How can I use these two variables here (within the same webpage) to load them into a MySQL table?

Thanks a lot!!!

You use the same code that you would if you were passing it to another file, there isn’t anything different when using the one file compared to two.

Thanks a lot.

Could you please give me an example showing how to get the values from the form and then load them into the database, all within the same webpage?

I think this is what he’s looking for. An example:


<?php

require_once('includes/database_functions.php');
require_once('includes/location_functions.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$sname = $_POST['Student_Name'];
$pname = $_POST['Parent_Name'];
$success = database_insert(sprintf("insert into registrations (sname, pname) values ('%s','%s')", $sname, $pname));
if ($success == true)
redirect_to('Success.php');
// if first display, or error, the html below will show.
// on error, text boxes will have previously entered values.
}
?>
<html>
<head>
<title>My Page</title>
</head>
<body>
<form action="target_webpage" method="post">
 <p>
 Nombre del alumno: <input type="text" class="lists_input" name="Student_Name" value="<?php echo($sname)?>" /><br>
 </p>
 <p>
 Nombre del apoderado: <input type="text" class="lists_input" name="Parent_Name" value="<?php echo($pname)?>" /><br>
 </p>
 </form>
</body>
</html>