Jump to content

[SOLVED] Does this look right?


tqla

Recommended Posts

Please take a look at this mysql string and tell me if it looks right

 

	$sql = "UPDATE member SET paydate=CURDATE(), status='regular', payamount=payamount+".$amount." , validitydate='".$validitydate."' WHERE id=".$_SESSION['userid'];

 

Why does validitydate have single and then double quotes and then concantenation? Also Why does $_Session have one "." before it?

 

It works but I've never seen it like this before.

 

Curious...

 

 

Link to comment
https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/
Share on other sites

Please take a look at this mysql string and tell me if it looks right

It works but I've never seen it like this before.

 

Sounds like you answered your own question.

 

If you understand correctly how an SQL UPDATE statement should look, how to give money and datetime data to a database, and how string concatenation in PHP works then it shouldn't be confusing at all.

It is almost stunning how sarcastic people are on this site... even the mods...

 

Well, a bit of independent thinking doesn't hurt you know. If it works then there isn't anything wrong with it. That's a logical truth. If there is something wrong with it then it doesn't work, so these are logical equivalents. Negating both of them will cause them to still have the same truth value.

Thanks roopurt18, I do understand and I would not have written it this way but I inherited it like this so I wasn't sure if there was something about it that I did not understand.

 

Thanks Matthew, ah ha,  I knew the concat was odd.

 

Thanks Maq. That makes more sense to me

 

But what of the "WHERE id=".$_SESSION['userid'];" ? Why the period before $_SESSION and not after too? Why is it there at all?

Because he's building a PHP string and concatenating the value of variables to it:

 

<?php
$sql = 
    "UPDATE member SET paydate=CURDATE(), status='regular', payamount=payamount+"                  // DOUBLE QUOTED PHP STRING

    . $amount                                                                     // CONCAT A PHP VARIABLE

    . " , validitydate='"                                                        // DOUBLE QUOTED PHP STRING

    . $validitydate                                                            // CONCAT A PHP VARIABLE

    . "' WHERE id="                                                             // DOUBLE QUOTED PHP STRING

    . $_SESSION['userid']                                                   // CONCAT A PHP VARIABLE

    ;                                                                               // END OF PHP STATEMENT
?>

 

It is almost stunning how sarcastic people are on this site... even the mods...

Everything I said was matter-of-fact, no sarcasm included.  :)

Daniel0, hey, I don't want to argue or anything but I did not ask if it was correct. I said, "It works but I've never seen it like this before." Hoping that someone could shed some light on this style of writing that I have never seen before. :)

 

Thanks all for the explanation. I understand it now. roopurt18 thanks for taking the time to break it out like that too.

It is almost stunning how sarcastic people are on this site... even the mods...

 

Well, a bit of independent thinking doesn't hurt you know. If it works then there isn't anything wrong with it. That's a logical truth. If there is something wrong with it then it doesn't work, so these are logical equivalents. Negating both of them will cause them to still have the same truth value.

 

I understand, it just would have been less typing to answer the question :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.