Jump to content

Basic question on update query


balorok

Recommended Posts

Okay,

 

So I'm trying to write a query that will update a certain value in my database, but I want it to update only when 3 conditions are met.  Basically, I want to update a column of ints in my DB (mysql) from 0 to a 1, if these criteria are met.  0 and 1 are the only values that are valid in this particular column. 

 

dbquery("UPDATE times SET approval = '1' WHERE id = '$id' AND time <= '$currentTime' AND project = '$project'");

 

that is my query.  Now, I'm not even sure if THIS part works.  It is however, slightly more complicated in that this query is actually embedded in a foreach loop:

 

$result = $_REQUEST["projects"];

$delimiter - ",";

$projectArray = explode($delimiter, $result);

 

foreach($projectArray as $project){

    dbquery("UPDATE times SET approval = '1'

                  WHERE id = '$id'

                  AND time <= '$currentTime'

                  AND project = '$project'");

}

 

If you can make any sense of that, and if you can point out any glaringly obvious mistakes here, I would appreciate it.  If you need any other information let me know.  Thank you all for your help.

 

 

Link to comment
Share on other sites

Actually, that was just a lost in translation typo... must have changed the = to a - while I was copying it. 

 

So, that wasn't the error, still won't update my DB correctly.  If I remove the last AND condition, it'll work, but it's updating more rows than I'd like it to.

 

I'm worried I don't have the right syntax to traverse my array and use each element in a query.

Link to comment
Share on other sites

Hey, thanks for that.  My query is sound, and it works. 

 

I had an error in my html call to a javascript that would execute the query located in the other php file.

 

get this:

 

<input type ="hidden" name="projects" valueS="<?php echo $array; ?>">

 

should have been

 

<input type ="hidden" name="projects" value="<?php echo $array; ?>">

 

without the damned S.  I'm sorry for wasting ya'lls time with what turned out to be my muddled, sleep deprived brain missing something simple.

 

I do appreciate your timely responses however, and your code snippet actually helped me identify that the problem was not with my query, but somewhere else, which let me track this down.

 

Once again, many, many thanks. 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.