I want to put two html edittext fields with a label next it saying please input a reg number and a button in the end, whereby the user can input a new registration number. I want to do it within the php script, but I don't know how to incorporate it
Thing is, I am not quite sure how to do this and how to validate the button on click. Like how do I get the values on button click?
This is what I have so far:
<?php
include "init.php"
if(!empty($_POST['driverNo'])){
$driverNoText = $_POST['driverNo'];
$stmt = "SELECT registrationNo FROM cars WHERE driverNo = ?";
$result = $conn->prepare( $stmt );
$result->bind_param( 's', $driverNoText );
$result->execute();
$result->store_result();
$result->bind_result( $registrationNo );
while( $result->fetch() )
{
echo $registrationNo;
}
$result->free_result();
?>
Is this even possible or would I have to create a html file and then include this php script?
Sorry, I am quite new to all this web dev stuff
Usually the flow for this kind of single purpose PHP file is that you can include html codes at the end of the PHP script. Treat PHP just like a html file, with a little bit advance thing that it's capable to do more than just HTML.
Which means, the file can be in this kind of format:
<?php
//------------------------
// Start of your php inits
// .....................
//------------------------
// Section where you have your code checking
//
if (!empty($_POST...
//do something useful, sanitize inputs, insert into db
//echo out something like "thanks for submission here"
} else {
//you can close the php tag here and put your html codes here
?>
<!doctype html>
.....
<form action="<?php echo $_SERVER['PHP_SELF'] ?>>
<input...>
<input type="submit" />
</form>
<?php
//and don't forget the closing bracket
}
If you are new and trying out PHP, go ahead and have this as the sample. This is generally not recommended anyway because it's a maintenance nightmare if your code grows. Generally you will need to look for frameworks that can help you with these tedious tasks.