I have this form that reads data from my DB and displays it so the user can edit those values but when I click on the form button nothing happens.
Here is my code:
Everything starts when I called this function that gets the info to display my form
static function ctrEditUser()
{
if (isset($_POST["userEdit"])) {
$data = AdminControl::ctrGetUser($_POST["userEdit"]);
$nombre = $data['userNombre'];
$aPaterno = $data["userPaterno"];
$aMaterno = $data["userMaterno"];
$movil = $data["userMovil"];
$token = $data["token"];
include $_SERVER["DOCUMENT_ROOT"] . "/view/pages/admin/admin.form.php";
}
}
This is my form
<div class="row">
<form class="columnas" method="post" action="" id="form">
<div class="columna1">
<br>
<div class="form-group">
<label class="adminText" for="adminName">Nombre(s):</label>
<input type="text" class="formcontrol" name="adminName" id="adminName" value="<?php echo $nombre ?>">
</div>
<br><br>
<div class="form-group">
<label class="adminText" for="adminPaterno">Apellido Paterno:</label>
<input type="text" class="formcontrol" name="adminPaterno" id="adminPaterno" value="<?php echo $aPaterno ?>">
</div>
</div>
<div class="columna2">
<br>
<div class="form-group">
<label class="adminText" for="adminMaterno">Apellido Materno:</label>
<input type="text" class="formcontrol" name="adminMaterno" id="adminMaterno" value="<?php echo $aMaterno ?>">
</div>
<br><br>
<div class="form-group">
<label class="adminText" for="adminMovil">Tel?©fono M??vil:</label>
<input type="number" class="formcontrol" name="adminMovil" id="adminMovil" placeholder="DEBEN SER SOLO 10 DIGITOS" value="<?php echo $movil ?>">
<span class="validity"></span>
</div>
<br><br>
<div class="save-button row">
<div class="form-group columna2">
<input type="submit" class="sysButton" style="margin-left: 300px;" name="saveButton" value="actualizar"></input>
</div>
</div>
</div>
</form>
</div>
As you can see is just a simple form.
Once I clicked the button I need to check the form and then save the new updated data
<?php
if (isset($_POST['saveButton'])) {
..... more code here
but when I clicked the button nothing at all happens, it never enters the IF statement, i really don??t know what is going wrong.
I already saw a lot of examples and I thonk everything is ok.
I appreciate any help.
This code came from a previous page where you can see the $token and$_POST["userEdit"]
<form method="post" class="btn">
<input type="hidden" value="<?php echo $value["token"] ?>" name="markUserDeleted">
<button type="submit" id="buttonDelete" class="btn-danger"><i class="fas fa-trash-alt"></i></button>
</form>
<td>
<form method="post" class="btn">
<input type="hidden" value="<?php echo $value["token"] ?>" name="userEdit">
<button type="submit" id="buttonEdit"><i class="fas fa-edit"></i></button>
</form>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php
if (isset($_POST["markUserDeleted"])) {
$response = AdminControl::ctrDeleteUser();
} elseif (isset($_POST["userEdit"])) {
$response = AdminControl::ctrEditUser();
}
?>
</div>
</body>
This code shows a table with db data, when you click on the blue button calls the functionAdminControl::ctrEditUser();
Problem is that your variable names are completely messed, if you print all the variables that are created in the form with the following code:
print_r($_POST);
Output is (after already inserting some data):
Array ( [adminName] => 123 [adminPaterno] => 159 [adminMaterno] => 3333 [adminMovil] => 54515456484 [saveButton] => actualizar )
You can see that there is nothing nameduserEdit
, there is actually nothing from your named variables. Even the English/Portugal versions of variable names are messed up. Here is code that actually works (assuming the file is named test.php)
<!DOCTYPE html>
<html lang='en'>
<head>
<?php
print_r($_POST);
if (isset($_POST["adminName"])) {
$nombre = $_POST["adminName"];
$aPaterno = $_POST["adminPaterno"];
$aMaterno = $_POST["adminMaterno"];
$movil = $_POST["adminMovil"];
//$token = $data["token"]; - no idea where you take this from
}
?>
</head>
<div class="row">
<form class="columnas" method="post" action="test.php" id="form">
<div class="columna1">
<br>
<div class="form-group">
<label class="adminText" for="adminName">Nombre(s):</label>
<input type="text" class="formcontrol" name="adminName" id="adminName" value="<?php echo $nombre ?>">
</div>
<br><br>
<div class="form-group">
<label class="adminText" for="adminPaterno">Apellido Paterno:</label>
<input type="text" class="formcontrol" name="adminPaterno" id="adminPaterno" value="<?php echo $aPaterno ?>">
</div>
</div>
<div class="columna2">
<br>
<div class="form-group">
<label class="adminText" for="adminMaterno">Apellido Materno:</label>
<input type="text" class="formcontrol" name="adminMaterno" id="adminMaterno" value="<?php echo $aMaterno ?>">
</div>
<br><br>
<div class="form-group">
<label class="adminText" for="adminMovil">Tel?©fono M??vil:</label>
<input type="number" class="formcontrol" name="adminMovil" id="adminMovil" placeholder="DEBEN SER SOLO 10 DIGITOS" value="<?php echo $movil ?>">
<span class="validity"></span>
</div>
<br><br>
<div class="save-button row">
<div class="form-group columna2">
<input type="submit" class="sysButton" style="margin-left: 300px;" name="saveButton" value="actualizar"></input>
</div>
</div>
</div>
</form>
</div>
</html>
You might want to add more checks in the php part, it is up to you, I have checked just one of the variables.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.