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 Link to comment https://forums.phpfreaks.com/topic/279171-i-need-help-to-insert-some-data-in-mysql/ Share on other sites More sharing options...
kimi2k Posted June 14, 2013 Share Posted June 14, 2013 You're foreget bracket in your query: mysql_query("INSERT INTO myDataBase (stringData) VALUES ('{$myString}')"); Link to comment https://forums.phpfreaks.com/topic/279171-i-need-help-to-insert-some-data-in-mysql/#findComment-1436040 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(); Link to comment https://forums.phpfreaks.com/topic/279171-i-need-help-to-insert-some-data-in-mysql/#findComment-1436077 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 Link to comment https://forums.phpfreaks.com/topic/279171-i-need-help-to-insert-some-data-in-mysql/#findComment-1436116 Share on other sites More sharing options...
filoaman Posted June 15, 2013 Author 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(); 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 Link to comment https://forums.phpfreaks.com/topic/279171-i-need-help-to-insert-some-data-in-mysql/#findComment-1436117 Share on other sites More sharing options...
filoaman Posted June 15, 2013 Author 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 Link to comment https://forums.phpfreaks.com/topic/279171-i-need-help-to-insert-some-data-in-mysql/#findComment-1436118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.