1

First of all, I know mysql is deprecated. Will change to mysqli as soon as I figure out the issue at hand. My query continues to update all my rows even if the data is not set in the 'stripetoken' column. Why is this happening?

Code snippet:

$token_query = 'SELECT * FROM jobsubmission';
$token_res = mysql_query($token_query);
$token_row = mysql_fetch_array($token_res);


if(isset($token_row['stripetoken'])) {
    $updqry = 'UPDATE jobsubmission SET assigned=1 WHERE ID="'.$book_ids[$jcount].'"';
    $update = mysql_query($updqry);
    $bookdate = date("d-m-Y");
3
  • Please note that mysql_* is now deprecated as of PHP7 because of security issues. It is suggested that you switch to mysqli_* or PDO extensions. Commented Apr 21, 2016 at 0:33
  • 1
    @PedroLobito Thanks Pedro. If you read my preliminary paragraph you would see that I had acknowledged that Commented Apr 21, 2016 at 1:06
  • Why don't you actually fetch it ? while ($token_row = mysql_fetch_array($token_res)) { if ($token_row['stripetoken']... Commented Apr 21, 2016 at 1:22

2 Answers 2

3

Because $token_row['stripetoken'] is always set because it is a column in your database and it will be available in $token_row as a result. Now whether it has a value or not is a different story. You should be using empty() instead (assuming you don't want it to be true for falsy values).

if(!empty($token_row['stripetoken'])) {
Sign up to request clarification or add additional context in comments.

6 Comments

Nice to see you back John ;-)
@Fred-ii- I'm trying to answer a question or two if I can help it. :)
You seem to be doing well :-)
Life is good. :) I should jump in the chat room and say hi sometime soon.
That's great John, I'm glad to hear it. Life's good here too :-) Looking forward to it, cheers
|
0

So while @JohnConde was absolutely correct in saying I needed to use the empty function over the isset, my solution layed elsewhere. Here is how I managed to get the query to work to my specifications:

  • instead of searching for empty, I made the 'stripetoken' column NULL by default.
  • This allowed me to use the following code:

    $token_query = 'SELECT * FROM jobsubmission WHERE ID="'.$book_ids
    [$jcount].'" and stripetoken is not null';
    $token_res = mysql_query($token_query);
    $token_row = mysql_fetch_object($token_res);
    
    if(!$token_row->stripetoken == NULL) {
    

1 Comment

FYI, empty() does exactly the same thing

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.