krausehaus2 Posted November 28, 2006 Share Posted November 28, 2006 I have a question about which to use around variables while sending a query to MS SQL. If I try to use single quotations around a variable my users cannot use contractions (can't, don't etc.). If I use quotation marks around my variable my users cannot use quotation marks.Okay to give you an idea of what is goin on I have written an online program for my employer to hold a customer database, computers that come in to get fixed get logged in, and the techs use the program to update online what they have done to the computer so that the customers can check online the status of their computer. So when the techs try to use an appostrophe the database fails. Here's an example: $query = "Insert into pc_completed values (\"$customer_id\", \"$customer_lname\", \"$customer_fname\", \"$customer_address\", \"$customer_city\", \"$customer_state\", \"$customer_zip\", \"$customer_phone\", \"$alt_phone\", \"$admin_user\", \"$computer_problem\", \"$trc_store\", \"$customer_passwd\", \"$date_in\", \"$date_completed\", \"$customer_call_1\", \"$customer_call_2\", \"$work_completed\", \"$work_completed_1\", \"$work_completed_2\", \"$tech_assigned\", \"$reason_for_call_1\", \"$reason_for_call_2\");";Using the quotation marks around the variable the techs can now use contractions. But they cannot use quotation marks in the program itself. When PHP sends it to the database the query fails. If anyone knows why or has a helpfull hint it would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/28739-deciding-whether-to-use-single-quotes-or-quotation-marks-around-variables/ Share on other sites More sharing options...
MCP Posted November 29, 2006 Share Posted November 29, 2006 This should allow you to do handle anything in the fields:[code=php:0]$customer_id = str_replace("'","''",$customer_id);$customer_lname = str_replace("'","''",$customer_lname);$customer_fname = str_replace("'","''",$customer_fname);$customer_address = str_replace("'","''",$customer_address);$customer_city = str_replace("'","''",$customer_city);$customer_state = str_replace("'","''",$customer_state);$customer_zip = str_replace("'","''",$customer_zip);$customer_phone = str_replace("'","''",$customer_phone);$alt_phone = str_replace("'","''",$alt_phone);$admin_user = str_replace("'","''",$admin_user);$computer_problem = str_replace("'","''",$computer_problem);$trc_store = str_replace("'","''",$trc_store);$customer_passwd = str_replace("'","''",$customer_passwd);$date_in = str_replace("'","''",$date_in);$date_completed = str_replace("'","''",$date_completed);$customer_call_1 = str_replace("'","''",$customer_call_1);$customer_call_2 = str_replace("'","''",$customer_call_2);$work_completed = str_replace("'","''",$work_completed);$work_completed_1 = str_replace("'","''",$work_completed_1);$work_completed_2 = str_replace("'","''",$work_completed_2);$tech_assigned = str_replace("'","''",$tech_assigned);$reason_for_call_1 = str_replace("'","''",$reason_for_call_1);$reason_for_call_2 = str_replace("'","''",$reason_for_call_2);$query = "Insert into pc_completed values ('$customer_id', '$customer_lname', '$customer_fname', '$customer_address', '$customer_city', '$customer_state', '$customer_zip', '$customer_phone', '$alt_phone', '$admin_user', '$computer_problem', '$trc_store', '$customer_passwd', '$date_in', '$date_completed', '$customer_call_1', '$customer_call_2', '$work_completed', '$work_completed_1', '$work_completed_2', '$tech_assigned', '$reason_for_call_1', '$reason_for_call_2')";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28739-deciding-whether-to-use-single-quotes-or-quotation-marks-around-variables/#findComment-131911 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.