tqla Posted June 1, 2009 Share Posted June 1, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/ Share on other sites More sharing options...
roopurt18 Posted June 1, 2009 Share Posted June 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847281 Share on other sites More sharing options...
MatthewJ Posted June 1, 2009 Share Posted June 1, 2009 validitydate is surrounded with single quotes because it is not a numeric value. Since the string is wrapped in double quotes, the concat is unnecessary. Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847283 Share on other sites More sharing options...
MatthewJ Posted June 1, 2009 Share Posted June 1, 2009 It is almost stunning how sarcastic people are on this site... even the mods... Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847284 Share on other sites More sharing options...
Maq Posted June 1, 2009 Share Posted June 1, 2009 You could rewrite it like this (there are certain rules for interpolating strings). $sql = "UPDATE member SET paydate='CURDATE()', status='regular', payamount=payamount+$amount, validitydate='$validitydate' WHERE id={$_SESSION['userid']}; Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847286 Share on other sites More sharing options...
Daniel0 Posted June 1, 2009 Share Posted June 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847287 Share on other sites More sharing options...
tqla Posted June 1, 2009 Author Share Posted June 1, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847290 Share on other sites More sharing options...
tqla Posted June 1, 2009 Author Share Posted June 1, 2009 Daniel0, I independently thought the heck out of it and couldn't find reference to this style of writing mysql queries. So, since I want to completely understand PHP, I asked here. Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847291 Share on other sites More sharing options...
Daniel0 Posted June 1, 2009 Share Posted June 1, 2009 That's not what I (or roopurt for that matter) is talking about. The fact that your query executes and has the correct side effects means it is correct. Asking whether or not it is correct when you've just found out that is redundant. Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847294 Share on other sites More sharing options...
Ken2k7 Posted June 1, 2009 Share Posted June 1, 2009 It's the way you concatenate strings in PHP. Example: <?php $name = 'Ken2k7'; $e = 'hello my name is ' . $name; I have the dot for concatenation, but I don't have anything else to concatenate after that, so I don't need a dot after it. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847295 Share on other sites More sharing options...
roopurt18 Posted June 1, 2009 Share Posted June 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847296 Share on other sites More sharing options...
tqla Posted June 1, 2009 Author Share Posted June 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847299 Share on other sites More sharing options...
MatthewJ Posted June 2, 2009 Share Posted June 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160547-solved-does-this-look-right/#findComment-847764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.