0

I want to change the variables in the column ->completedstatus in my mysql database to 1 with a click on a button. Those variables are 0 now. i only have an echo now of the Completed variable value.

<?if ($row->Completed == 1)
{
    echo "Afgerond";
}
else {
    echo "Niet afgerond";
}      
?>

this will output the right thing. But how do i change the variable in the mysql database with an click on a button?

3
  • 1
    write <?php if.. instead of <?if... Commented Feb 14, 2014 at 8:28
  • have you tried $row->completedstatus = 1 Commented Feb 14, 2014 at 8:31
  • If you want to update value in database, you need at least basic knowlege about managing mysql in php. Commented Feb 14, 2014 at 8:31

3 Answers 3

2

Try it like this (Not tested), but it should be like this

 <input type="text" name="halo"/>
        <input type="button" value="submit"/>
        <?php
            if(isset($_POST['halo']))
            {
                $hoi = $_POST['halo'];
                mysqli_query("INSERT INTO 'db_name' . 'table_name' 'row_name')
                    VALUES('{$hoi}')");     
            }
        ?>
Sign up to request clarification or add additional context in comments.

Comments

0

You need to write a MySQL query white updates the row and execute it seperately.

If you don't want to do raw database operations I'd recommend using an ORM library to bind your php objects to DB.

Comments

0

See this for connecting to database: http://php.net/manual/en/pdo.exec.php

and this for an MYSQL update syntax: http://dev.mysql.com/doc/refman/5.0/en/update.html

2 Comments

My connection to the database works. because the echo works. but i dont know how to update the syntax with an html button. is it even possible?
do you use active record or SQL? Here are some examples of them: ellislab.com/codeigniter/user-guide/database/examples.html

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.