1

I am having problems concatenating a variable to a number (with the variable first, because $info1002 is not a known variable), I appreciate my problem here must be my single double quotations and I've tried a lot of combinations and my googling hasn't helped.

mysql_query("INSERT INTO users (ID, info1) VALUES ('','.$info.''002')")or die(mysql_error());

4 Answers 4

4

you need to format it like this:

mysql_query("INSERT INTO users (ID, info1) VALUES ('','".$info."002')") or die(mysql_error());

Also, if you have the ID field set to AutoIncrement, you can ommit it like this:

mysql_query("INSERT INTO users (info1) VALUES ('".$info."002')") or die(mysql_error());

This will insert value of $info followed by 002 into the database.

Sign up to request clarification or add additional context in comments.

1 Comment

works +1, personally i like to keep my AI's visible so i remember what the H i'm trying to do! Thanks
2
mysql_query("INSERT INTO users (ID, info1) VALUES ('','".$info."002"')")or die(mysql_error());

Comments

1

why don't you concatenate if before adding it to the query? I think it is much easier so you don't have that mass with quotation.

$var = $info.'002';
mysql_query("INSERT INTO users (ID, info1) VALUES (null ,'".$var."') or die(mysql_error());

Comments

0
mysql_query("INSERT INTO users (info1) VALUES ('{$info}002')")or die(mysql_error());

It may not work only if your ID is set NOT NULL and it not set as autoincrement!

1 Comment

The page threw a syntax error... you have an ' too many maybe?

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.