0

Hi I am trying to create a table like '$username'_package in google mysql cloud. I could create table successfully but it actually create a table with name like this say '[email protected].'_pakage but I actually need to create a table with name like [email protected]_package. This my query,

mysql_query("CREATE TABLE `db`.`{$email_append}` (`id` int(25) NOT NULL,`packageid` int(25) NOT NULL,`package_name` varchar(35) NOT NULL,`category` varchar(24) NOT NULL,`description` varchar(24) NOT NULL,`sub_description` varchar(25) NOT NULL,`default_price` int(25) NOT NULL,`custom_price` int(25) NOT NULL,`force_amount` int(25) NOT NULL,`percent_discount` int(25) NOT NULL,`package_total` int(25) NOT NULL)");

These are the try that I have made,

1.'".$username."'
2.'$username'
3.`$username`
4.I created a php variable "$email_append" and concat it with "_package".

Every try gave me the same results. How to solve this. Can someone help me? Thanks in advance.

1 Answer 1

1

You can concat like that:

`db`.`{".$email."_append}`

Example:

$email = 'test';
echo "CREATE TABLE `db`.`".$email."_append` (`id` int(25) NOT NULL,`packageid` int(25) NOT NULL,`package_name` varchar(35) NOT NULL,`category` varchar(24) NOT NULL,`description` varchar(24) NOT NULL,`sub_description` varchar(25) NOT NULL,`default_price` int(25) NOT NULL,`custom_price` int(25) NOT NULL,`force_amount` int(25) NOT NULL,`percent_discount` int(25) NOT NULL,`package_total` int(25) NOT NULL)";

Result:

CREATE TABLE `db`.`test_append` 
(
`id` INT(25) NOT NULL,
`packageid` INT(25) NOT NULL,
`package_name` VARCHAR(35) NOT NULL,
`category` VARCHAR(24) NOT NULL,
`description` VARCHAR(24) NOT NULL,
`sub_description` VARCHAR(25) NOT NULL,
`default_price` INT(25) NOT NULL,
`custom_price` INT(25) NOT NULL,
`force_amount` INT(25) NOT NULL,
`percent_discount` INT(25) NOT NULL,
`package_total` INT(25) NOT NULL
)

Issue:

In your code {$email_append} its treated as a full variable, which is not you need to concat $email and _append.

Side Note:

Please use mysqli_* or PDO instead of mysql_* its deprecated and not available in PHP 7.

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

2 Comments

That worked fine for me and you have helped me identify my mistake... @devpro
glad to help u @Anu: :)

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.