fillfry Posted March 31, 2011 Share Posted March 31, 2011 I have received this in the php error log: PHP Warning: mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: message: Line 1: Incorrect syntax near '='. (severity 15) coming from somewhere in here: $query = "UPDATE student_info SET f_name = '".$post_vars['f_name']."', m_name = ". wrap($post_vars['m_name']) .", l_name = '".$post_vars['l_name']."', email_personal = '".$post_vars['email_personal']."', phone_number = '".$post_vars['phone_number']."', contact_method = '".$post_vars['contact_method']."', date_submitted = '".date('Y/m/d')."', gender = '".$post_vars['gender']."' WHERE cwid = ".$cwid; if(!($result = mssql_query($query))) die("Database Error: you might have already submitted the form. Error 1<br/>" . $footer); I am semi new to php and I acquired this with the job... Any help or suggestions would be AWESOME!!!! Thanks Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/ Share on other sites More sharing options...
Maq Posted March 31, 2011 Share Posted March 31, 2011 I'm going to guess that the value here needs single quotes, like this: m_name = '". wrap($post_vars['m_name']) ."' Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/#findComment-1195141 Share on other sites More sharing options...
fillfry Posted March 31, 2011 Author Share Posted March 31, 2011 Thanks Maq! When I added the single quotes I received the same error as before, just with ...Incorrect syntax near 'm_name'... early on, I thought it had something to do with the if(!($result = mssql_query($query))) die(...) cause those are the lines that the error_reporting(E_ALL) is giving me in the browser Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/#findComment-1195149 Share on other sites More sharing options...
Maq Posted March 31, 2011 Share Posted March 31, 2011 Can you post the exact error message & the new query? Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/#findComment-1195151 Share on other sites More sharing options...
fillfry Posted March 31, 2011 Author Share Posted March 31, 2011 Warning: mssql_query() [function.mssql-query]: message: Line 1: Incorrect syntax near 'Testing'. (severity 15) $query = "UPDATE student_info SET f_name = '".$post_vars['f_name']."', m_name = '". wrap($post_vars['m_name']) ."', l_name = '".$post_vars['l_name']."', email_personal = '".$post_vars['email_personal']."', phone_number = '".$post_vars['phone_number']."', contact_method = '".$post_vars['contact_method']."', date_submitted = '".date('Y/m/d')."', gender = '".$post_vars['gender']."' WHERE cwid = ".$cwid; Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/#findComment-1195153 Share on other sites More sharing options...
Maq Posted March 31, 2011 Share Posted March 31, 2011 I'm guessing the value 'Testing' is in the variable $post_vars['m_name']? Can you echo out your $query statement and post it here? Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/#findComment-1195160 Share on other sites More sharing options...
fillfry Posted March 31, 2011 Author Share Posted March 31, 2011 this is what I get when I echo the $query: UPDATE student_info SET f_name = 'firstnameTest', m_name = ''Testing'', l_name = 'lastnameTest', email_personal = '[email protected]', phone_number = '000-000-0000', contact_method = 'email', date_submitted = '2011/03/31', gender = 'M' WHERE cwid = 000000000 Warning: mssql_query() [function.mssql-query]: message: Line 1: Incorrect syntax near 'Testing'. (severity 15) Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/#findComment-1195176 Share on other sites More sharing options...
Maq Posted March 31, 2011 Share Posted March 31, 2011 OK, I didn't know your wrap() function just put single quotes around the value. Is there a specific reason you're using that function? Other than that your query looks fine. The only other thing I can suggest is getting rid of the wrap() function and just putting single quotes there manually like the other values. Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/#findComment-1195184 Share on other sites More sharing options...
fillfry Posted March 31, 2011 Author Share Posted March 31, 2011 Yeah, apparently. Thanks a lot, that worked. Now on to the other errors in the same file!!! Here is the wrap(): function wrap($it, $d = "'"){ if($it){ if(is_numeric($it)){ return $it; }else{ return $d . $it . $d; } }else{ return 'NULL'; } } Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/#findComment-1195193 Share on other sites More sharing options...
Maq Posted March 31, 2011 Share Posted March 31, 2011 I see what you're trying to do there. Be careful because you're checking if a number is numeric on the PHP side, which is loosely typed, also sometimes you may want to store numerics in a VARCHAR column. Link to comment https://forums.phpfreaks.com/topic/232323-php-warning-mssql_query/#findComment-1195195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.