Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

updating/deleting form data with php to update database using phpmyadmin

I am in the midst of completing a uni assignment and ive come across the issue of being totally stumped on how to update and delete data in my database through the use of a form.

I have successfully connected the database so that when the user selects the the addressID in the previous page they wish to work on, it will take 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>

I am now completely stumped on how to connect the data they enter in the form to update the database.

I am trying to update the addresses table with the selected addressID chosen earlier if that helps.

Any push in the correct direction will be greatly appeciated.

Kind Regards

like image 986
geebee Avatar asked Oct 29 '22 18:10

geebee


1 Answers

Change these 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
}
like image 60
Mayank Pandeyz Avatar answered Nov 10 '22 07:11

Mayank Pandeyz