1

I have a variable like this:

$var = "INSERT INTO `gaz_001rigdoc`(`id`) VALUES (".$variabletest.");";

Afterwards, I need do this:

$querygo = mysql_query ($var);

Is this possible? How can I do this? Thank you.

7
  • yes it is possible... you just did it... Commented Sep 25, 2015 at 10:06
  • I try but don't work Commented Sep 25, 2015 at 10:07
  • 2
    You should not use the deprecated mysql_* API. use mysqli_* or PDOwith prepared statements Commented Sep 25, 2015 at 10:07
  • print the query and check Commented Sep 25, 2015 at 10:08
  • 1
    Add single quotes arround the value $var = "INSERT INTO gaz_001rigdoc(id) VALUES ('".$variabletest."')"; Commented Sep 25, 2015 at 10:08

3 Answers 3

2

Mysql query need ' ' with every string

$var = "INSERT INTO `gaz_001rigdoc`(`id`) VALUES ('$variabletest')";
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

$var = "INSERT INTO gaz_001rigdoc(id) VALUES ('".$variabletest."')";

2 Comments

It work man. Thank you. I have a very long variable and i don't remember the '' between the value. Thank you again!
In that case please have a read of docs.php.net/security.database.sql-injection (chances are you haven't considered it yet).
1

Ofcourse you could do that:

$variabletest = 123;

$var = "INSERT INTO `gaz_001rigdoc`(`id`) VALUES ('$variabletest')";

$querygo = mysqli_query($con, $var);

Notice: $con is a connection made variable in mysqli.

2 Comments

Might have been something fancy I didn't know about ;)
@Epodax Ahh, I see what you did there ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.