westonm Posted December 26, 2012 Share Posted December 26, 2012 I have been having a problem with a very simple function for about the last 6 hours and it is getting real frustrating. I am quite sure it is a very simple something I am overlooking but I don't see it. If someone could point me in the right direction I would greatly appreciate it. The code is in the attached file: The problem is that I am passing a value of "MaynardWestonA" which is a key to a SQL table. In the function I want to update the record for "MaynardWestonA" but it keeps seeing only "Mayna" in the function- it is dropping the rest of the variable and consequently not finding the record. function updtRegis($keyin) { UPDATE directory SET username='', password='', registered='Yes' WHERE key = $keyin ; } The main program calls the function as follows: $keypass = 'MaynardWestonA' ... rtnvalue2 = updtRegis($keypass); UpdateSnip.txt Quote Link to comment https://forums.phpfreaks.com/topic/272384-puzzling-problem-with-function-variable/ Share on other sites More sharing options...
Pikachu2000 Posted December 26, 2012 Share Posted December 26, 2012 That code won't even parse. Paste the actual code here within . . . tags. Quote Link to comment https://forums.phpfreaks.com/topic/272384-puzzling-problem-with-function-variable/#findComment-1401392 Share on other sites More sharing options...
westonm Posted December 26, 2012 Author Share Posted December 26, 2012 Sorry - I thought the basics idea would be enough - The actual code is function updtRegist($keyin, $database_Class63, $Class63) { require_once('Connections/Class63.php'); mysql_select_db($database_Class63, $Class63); $updateSQL = sprintf("UPDATE 'directory' SET 'USERNAME'='','PASSWORD'='','Registered'='Yes' WHERE 'KEY'=%s", GetSQLValueString($keyin, "text")); $Result1 = mysql_query($updateSQL, $Class63) or die(mysql_error()); } The calling code is $rtnval2 = updtRegist($keypass, $database_Class63, $Class63); Why can't I do a line feed here? This is just the function and the calling code. Quote Link to comment https://forums.phpfreaks.com/topic/272384-puzzling-problem-with-function-variable/#findComment-1401406 Share on other sites More sharing options...
Barand Posted December 26, 2012 Share Posted December 26, 2012 (edited) Do not put table name and column names in single quotes  %s should be in single quotes Edited December 26, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/272384-puzzling-problem-with-function-variable/#findComment-1401410 Share on other sites More sharing options...
westonm Posted December 26, 2012 Author Share Posted December 26, 2012 Barand - Thanks this seemed to help, it passed the full value of the variable. Didn't update the table but I am a step closer now, at least it is not giving me an error. I have always had a problem with single and double quotes and when to use them or not. Actually had to leave the single quotes on KEY and not put them on %s. I think it needs them on KEY since that is a reserved name. Thanks again, now I can find the next problem. Quote Link to comment https://forums.phpfreaks.com/topic/272384-puzzling-problem-with-function-variable/#findComment-1401416 Share on other sites More sharing options...
Barand Posted December 26, 2012 Share Posted December 26, 2012 Use backticks `KEY`, not quotes. Â String variables like %s need quoting otherwise SQL thinks they are column names Quote Link to comment https://forums.phpfreaks.com/topic/272384-puzzling-problem-with-function-variable/#findComment-1401417 Share on other sites More sharing options...
Pikachu2000 Posted December 26, 2012 Share Posted December 26, 2012 DB/table/field names are never enclosed in quotes (in MySQL, anyhow. Don't know about the rest). If they happen to be a reserved word, the best thing is to rename the entity, the next best thing is to enclose the name in `backticks`. Quote Link to comment https://forums.phpfreaks.com/topic/272384-puzzling-problem-with-function-variable/#findComment-1401418 Share on other sites More sharing options...
westonm Posted December 27, 2012 Author Share Posted December 27, 2012 Thanks much guys - got it working now. Using backticks on KEY let it do the update. Quote Link to comment https://forums.phpfreaks.com/topic/272384-puzzling-problem-with-function-variable/#findComment-1401420 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.