0

My goal is to change the value in the "commission" column from 'open' to 'closed' when I update the table 'status'.I can't seem to get the DB to update. I do not get any errors. What am I doing wrong?

This is the code for my submit button:

if($result["commissions"]=='open'){
    echo '<form method="post" action="admin_main.php">
    <input name="commissionsC" type="submit" value="Close comissions" />
    </form>';
    }

This is the part of my code that is not working:

<?php 
include("includes/connect.php");
if(isset($_POST['comissionsC'])){ 

$res= mysql_query("SELECT * FROM status");
$row= mysql_fetch_array($res);
$sql="UPDATE status".
"SET commissions = 'closed'".
"WHERE id = 1";
}

?>
5
  • 1
    That is because you are not executing the query at all. Commented Apr 5, 2014 at 12:35
  • You don't seem to execute the UPDATE statement in your code. Commented Apr 5, 2014 at 12:36
  • also give a space after status" status " Commented Apr 5, 2014 at 12:37
  • So what I need to add is? (Sorry I am being stupid here) Commented Apr 5, 2014 at 12:45
  • Consult my answer @CathrineRydning => stackoverflow.com/a/22881505 Commented Apr 5, 2014 at 13:31

3 Answers 3

1

Change your query to:

$sql = mysql_query("UPDATE status SET commisions = 'closed' WHERE id = 1");

You're not executing your query.


Footnotes:

mysql_* functions deprecation notice:

http://www.php.net/manual/en/intro.mysql.php

This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.

These functions allow you to access MySQL database servers. More information about MySQL can be found at » http://www.mysql.com/.

Documentation for MySQL can be found at » http://dev.mysql.com/doc/.

Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome Cathrine. If my answer did solve it, consider clicking the White (gray outline) tick/checkmark till it turns Green next to my answer to mark as answered. Otherwise, your question will remain in the unanswered category. @CathrineRydning
0

is it always id number 1 that you want to update? Maybe you have to get the number id for each data :

$sql = mysql_query(UPDATE status SET commisions = "closed" WHERE id = 1)

2 Comments

It is always ID number 1 I want :)
if that so.. WHERE id = 1 because as I know, if the data is number, it doesn't need use ' '.
0

Once u get the datas, execute the update query as well

$res= mysql_query("SELECT * FROM status");
$row= mysql_fetch_array($res);

$sql = mysql_query(UPDATE status SET commisions = "closed" WHERE id = 1)

1 Comment

Your answer will fail. It should be $sql = mysql_query("UPDATE status SET commisions = 'closed' WHERE id = '$id'") if anything. However OP wants it to be id=1

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.