Jump to content

I need help to insert some data in mysql


filoaman

Recommended Posts

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  

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();

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  :-\

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  :happy-04:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.