durgaprasadcs Posted December 30, 2013 Share Posted December 30, 2013 Hello , I have a Query to insert values to database. The Query is working fine sometimes and sometimes not. Here is the Query I have $sql = "INSERT INTO snicyposts (MAKE,MODEL,VARIANT,YEAR,COLOUR,FUELTYPE,MILEAGECITY,MILEAGEHIGHWAY,KILOMETERS,TITLE,DESCRIPTION,FEATUES,PRICE,NEGOTIABLE,SCRATCH,OWNERTYPE,CITY,ACCIDENT,TYPE,POSTEDBY,PHONE,POSTEDBYEMAIL,POSTEDON,POSTEDBYUSERNAME,IPADDRESS,POWERSTEERING,POWERWINDOWS,INSURANCEVALIDITY,REGISTRATIONTYPE) VALUES ( '$make','$model','$variant','$year','$colour','$fueltype','$citymil','$highmil','$km','$title','$desc','$features','$price','$negotiable','$scratc','$owner','$city','$accidents','$type','$name','$phone','$email','$currenttime','$usernameposted','$ipadd','$powersteering','$powerwindows','isurance','$regtype')"; mysql_query($sql); Please help me to solve this Quote Link to comment https://forums.phpfreaks.com/topic/284973-my-sql-insert-into-sometimes-working-and-sometimes-not/ Share on other sites More sharing options...
Barand Posted December 30, 2013 Share Posted December 30, 2013 Have you tried echoing the output from mysql_error() to find the reason? And do you really have a column named "FEATUES"? Quote Link to comment https://forums.phpfreaks.com/topic/284973-my-sql-insert-into-sometimes-working-and-sometimes-not/#findComment-1463287 Share on other sites More sharing options...
durgaprasadcs Posted December 30, 2013 Author Share Posted December 30, 2013 (edited) Yes I have a column like FEATUES and I have tried echoing,the format and all perfect. Issue is if it is not working entirely I can able to find the root cause, but its sometimes working and sometimes not. That's the problem. Is there any problem with my host ? even I tried with them , but they said there is no problem in their server. Edited December 30, 2013 by durgaprasadcs Quote Link to comment https://forums.phpfreaks.com/topic/284973-my-sql-insert-into-sometimes-working-and-sometimes-not/#findComment-1463333 Share on other sites More sharing options...
Barand Posted December 30, 2013 Share Posted December 30, 2013 Have you tried echoing the output from mysql_error() to find the reason? If the query fails, check out why! if (!mysql_query($sql)) die (mysql_error() . "<pre>$sql</pre>"); Quote Link to comment https://forums.phpfreaks.com/topic/284973-my-sql-insert-into-sometimes-working-and-sometimes-not/#findComment-1463335 Share on other sites More sharing options...
mac_gyver Posted December 30, 2013 Share Posted December 30, 2013 two possibilities come to mind - 1) you have some indexes/unique keys set up and you are tying to insert duplicate values. 2) you are not escaping the string data being put into the query and some data contains sql special characters. Quote Link to comment https://forums.phpfreaks.com/topic/284973-my-sql-insert-into-sometimes-working-and-sometimes-not/#findComment-1463348 Share on other sites More sharing options...
Solution durgaprasadcs Posted December 31, 2013 Author Solution Share Posted December 31, 2013 Hi Thanks!!! your reply help me to solve the issue. The thing is i didnt escape the string before adding. so whenever users used special characters, its not worked. That's the issue. Thanks a lot !!!! Quote Link to comment https://forums.phpfreaks.com/topic/284973-my-sql-insert-into-sometimes-working-and-sometimes-not/#findComment-1463407 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.