Reputation: 23
I am currently doing a school course project.It requires us to code out a website.We designed a website which provides online food ordering service to our school community.
I want to know how to change a data in a specific filed in mysql server by just clicking one button.
I designed a user profile page which shows the information of the users. They can see their previous orders by clicking "show orders" button. Then a table which contains the ordering information will be displayed.
I added a button behind each row called "Delivered". I wish that the Ordering_status can be changed from "ordering" to "delivered" when user click the "Delivered" button. I attached my layout page below.
https://www.dropbox.com/s/lyfjn9hed1zfjyd/user_profile.png
Could anyone kindly help me with this?
I cannot attach my code here. It will display in a mess manner. Please use the link below https://www.dropbox.com/s/u1h73lx07hrsr78/profile.php
Thank you!
<script>
function myfunction(int id)
{
$link=mysqli_connect("localhost","f34s25","f34s25","f34s25");
$a="UPDATE orders SET Ordering_status="delivered" where order_id=id;
$b=mysqli_query($a);
}
</script>
Upvotes: 1
Views: 5472
Reputation: 2956
one easy solution is that you assign a name to the button delivered.like this
<input type="submit" value="delivered" name="delivered">
and when the user will click this submit button take the value in the php part.and check whether it is clicked or not,like this
if(isset($_POST['delivered']))
{
$a="update yourtablename set Ordering_status="deleivered" where name="$name";
$b=mysqli_query($a);
}
Upvotes: 2