Jump to content

I need help to insert some data in mysql


filoaman
Go to solution Solved by 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  

Link to comment
Share on other sites

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
Share on other sites

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 by filoaman
Link to comment
Share on other sites

  • Solution

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:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.