filoaman Posted June 14, 2013 Share Posted June 14, 2013 Hi friends I'm trying to insert a string into a mysql database. The form of my string is this "1.32G3.33G0.67G1.66G0.88G9G14.56" I select "text" as Type. I put my string on variable $myString="1.32G3.33G0.67G1.66G0.88G9G14.56"; No i'm trying to insert this string to mu database using this code: mysql_query("INSERT INTO myDataBase (stringData) VALUES ('$myString'"); Nothing... What is wrong? Waiting for ideas. Thank you Quote Link to comment Share on other sites More sharing options...
kimi2k Posted June 14, 2013 Share Posted June 14, 2013 (edited) You're foreget bracket in your query: mysql_query("INSERT INTO myDataBase (stringData) VALUES ('{$myString}')"); Edited June 14, 2013 by kimi2k Quote Link to comment Share on other sites More sharing options...
DavidAM Posted June 15, 2013 Share Posted June 15, 2013 Brackets are not required for simple variable names in a string. But the closing parenthesis for the VALUES clause is missing. When mysql_query fails, it will return false. You can use mysql_error to find out why. Also, it is recommended that you build the query in a variable instead of executing directly. Then you can print the query along with the error, this will help you see what is wrong. $sql = "INSERT INTO myDataBase (stringData) VALUES ('$myString'"; $res = mysql_query($sql); if ($res === false) echo 'Query Failed: ' . $sql . ' Error: ' . mysql_error(); Quote Link to comment Share on other sites More sharing options...
filoaman Posted June 15, 2013 Author Share Posted June 15, 2013 You're foreget bracket in your query: mysql_query("INSERT INTO myDataBase (stringData) VALUES ('{$myString}')"); I try this, unfortunately doesn't work Quote Link to comment Share on other sites More sharing options...
filoaman Posted June 15, 2013 Author Share Posted June 15, 2013 (edited) Brackets are not required for simple variable names in a string. But the closing parenthesis for the VALUES clause is missing. When mysql_query fails, it will return false. You can use mysql_error to find out why. Also, it is recommended that you build the query in a variable instead of executing directly. Then you can print the query along with the error, this will help you see what is wrong. $sql = "INSERT INTO myDataBase (stringData) VALUES ('$myString'"; $res = mysql_query($sql); if ($res === false) echo 'Query Failed: ' . $sql . ' Error: ' . mysql_error(); I try this and yes I get an error but without any useful information. This is the error: Query Failed: INSERT INTO myDataBase (stringData) VALUES (1.32G3.33G0.67G1.66G0.88G9G14.56) Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'stringData) VALUES (1.32G3.33G0.67G1.66G0.88G9G14.56)' at line 1 I'm really stuck.... I don't understand where is the error Edited June 15, 2013 by filoaman Quote Link to comment Share on other sites More sharing options...
Solution filoaman Posted June 15, 2013 Author Solution Share Posted June 15, 2013 OK - I Did it!!!!!!! My error was that I had to include the (stringData) part on this type of quotes (`stringData`) !!!!!!!!!! Here is the code: $myString="1.32G3.33G0.67G1.66G0.88G9G14.56"; mysql_query("INSERT INTO myDataBase (`stringData`) VALUES ('$myString')"; Thank you for your help Quote Link to comment 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.