1

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>
2
  • To post the code, Please Use stackoverflow code format styling, in ASK question you can find ? symbol, you can click that to know the format and styling Commented Nov 8, 2013 at 4:30
  • I cannot post my codes correctly here. Anyone can help with this? Commented Nov 8, 2013 at 6:40

1 Answer 1

2

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);
}
Sign up to request clarification or add additional context in comments.

7 Comments

I believe your solution works.However the problem for me is that there might be a number of orders appearing. Thus, I need to echo out one button at the end of each order(row) to change the delivery status of each specific order(row). I think I may need to use the primary id in table to decide which to row to change. But I do not know how to implement it.
u mean u want to change the button.please be more specific about your doubt so that i can help you.
The fact is that when there is a new order showing, there should be a "delivered" button behind.(you can see the picture through my attached link). Each "delivered" button is to change one delivery status of one row(order). I do not know how to do this. Because there are multiple status which need be changed.
the above query which i wrote will update only one row the others will remain unaffected.use your unique id in where condition.please let me know if i am not clear at what i am saying.
i think email will be unique in your case so in update where condition take where email=$email than it will update the row having that particular email only.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.