Hi I am having trouble appending a value to a variable in an sql query.

I am using this line to add new tables to my database

$sql = "ALTER TABLE $skillstable ADD `$newtable1` VARCHAR( 32 ) NOT NULL";

where value for $skillstable is j_descriptor

I have now created more tables with names like.
j_descriptor_c1
j_descriptor_c7
j_descriptor_p1
j_descriptor_p7
j_descriptor_pc1
j_descriptor_pc7

so i effectively want the code to read like this

$sql = "ALTER TABLE $skillstable ADD `$newtable1` VARCHAR( 32 ) NOT NULL";
$sql = "ALTER TABLE $skillstable._c1 ADD `$newtable1` VARCHAR( 32 ) NOT NULL";
$sql = "ALTER TABLE $skillstable._c7 ADD `$newtable1` VARCHAR( 32 ) NOT NULL";
$sql = "ALTER TABLE $skillstable._p1 ADD `$newtable1` VARCHAR( 32 ) NOT NULL";
$sql = "ALTER TABLE $skillstable._p7 ADD `$newtable1` VARCHAR( 32 ) NOT NULL";
$sql = "ALTER TABLE $skillstable._pc1 ADD `$newtable1` VARCHAR( 32 ) NOT NULL";
$sql = "ALTER TABLE $skillstable._pc7 ADD `$newtable1` VARCHAR( 32 ) NOT NULL";

But I am clearly not appending the bit _c1 properly. Can you explain to me how to do it?

    You can't use a dot between quotes. The way to append the value to the string, is to put the variable outside te quotes like this:

    $sql = "ALTER TABLE ".$skillstable."_c1 ADD `$newtable1` VARCHAR( 32 ) NOT NULL";
      Write a Reply...