Update / delete form data using php to update the database using phpmyadmin

I am in the midst of completing an uni job, and I am faced with the problem of completely refusing to update and delete data in my database using a form.

I successfully connected the database so that when the user selects the address identifier on the previous page on which they want to work, he will transfer them to the updateform.php page.

My code for the form is as follows:

<form method="post"> <tr> <td>Firstline</td> <td><input type="text" name="firstline" class="form-control"/></td> </tr> <tr> <td>Secondline</td> <td><input type="text" name="secondline" class="form-control"/></td> </tr> <tr> <td>City</td> <td><input type="text" name="city" class="form-control"/></td> </tr> <tr> <td>State</td> <td><input type="text" name="state" class="form-control"/></td> </tr> <tr> <td>Zip</td> <td><input type="text" name="zip" class="form-control"/></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Update" class="btn btn-success btn-lg"/></td> </tr> <tr> <td></td> <td><input type="delete" name="submit" value="Delete" class="btn btn-success btn-lg"/></td> </tr> 

Now I absolutely do not understand how to connect the data that they enter in the form to update the database.

I am trying to update the address table with the selected address ID selected earlier if this helps.

Any push in the right direction will be strongly triggered.

Yours faithfully

+5
source share
2 answers

Change this line:

 <form method="post"> 

to

 <form method="post" action="process.php"> 

and

 <input type="submit" name="submit" value="Update" class="btn btn-success btn-lg"/> 

to

 <input type="submit" name="update" value="Update" class="btn btn-success btn-lg"/> 

and

 <input type="delete" name="submit" value="Delete" class="btn btn-success btn-lg"/> 

to

 <input type="delete" name="delete" value="Delete" class="btn btn-success btn-lg"/> 

process.php:

 if(isset($_REQUEST['update'])) { // update block // get all required value and fire update query } if(isset($_REQUEST['delete'])) { // delete block // get all required value and fire delete query } 
+2
source

You can try something like this:

updateform.php

  <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { 

separate tags from user input:

  $firstline= trim(strip_tags($_POST['first_line'])); $secondline= trim(strip_tags($_POST['second_line'])); 

create request:

  $myquery = "INSERT INTO tablename (firstline, secondline) VALUES ($firstline', '$secondline')"; 

execute the request (confirm success / failure if / else):

  if (@mysqli_query($database, $myquery)) { print '<p>Entries accepted</p>'; } else { print '<p style="color: red;">Could not INSERT values because:<br />' . mysqli_error($database) . '</p>; } } ?> 

Then enter the form values ​​for the query variables:

 <form action="updateform.php" method="post"> <tr> <td>Firstline</td> <td><input type="text" name="firstline" size="20" value= <?php if (isset($_POST['firstline'])) { print htmlspecialchars($_POST['first_line']); } ?> /></td> <tr> <td>Secondline</td> <td><input type="text" name="secondline" size="20" value= <?php if (isset($_POST['secondline'])) { print htmlspecialchars($_POST['second_line']); } ?> /></td> 

  <tr> <td></td> <td><input type="submit" name="submit" value="Update" class="btn btn-success btn-lg"/></td> </tr> <tr> <td></td> <td><input type="delete" name="submit" value="Delete" class="btn btn-success btn-lg"/></td> 

0
source

Source: https://habr.com/ru/post/1258624/


All Articles