1

I have a hidden input within a form. When I submit the form, I want to create a new column in a table named "answers" with a title based on the value of the hidden input.

CODE FOR FORM + HIDDEN INPUT

<form action="frameworkplayground.php" method="POST"> 
     <input type="hidden" name="LevelColumnAdder" value="Simplifying Fractions">  
     <input type="submit" id="samplesubmitbutton" value="Click Me">
</form>

CODE TO TAKE THE VALUE OF THE HIDDEN INPUT (NAMED "LevelColumnAdder") ADD THE WORD "Test" TO THE VALUE & USE THIS AS THE TITLE OF A NEW COLUMN.

<?php
   if(isset($_POST['LevelColumnAdder'])){
            $LevelColumnAdder=$_POST['LevelColumnAdder']; //Here, I'm trying to get the value of the input named LevelColumnAdder
            $db->query("ALTER TABLE answers ADD $LevelColumnAdder+"Test" VARCHAR( 255 ) NOT NULL");  //I know the +"Test" part is wrong but I don't know how to add "Test" to the value and use it as the new title
    }
?>

When this form is submitted, I ultimately want it to form a new column named "Simplifying Fractions Test" but nothing is happening.

Snoops
  • 215
  • 1
  • 12
  • 1
    rather unusual to alter a table structure like this. I think you need to re-access your table schema –  Jun 26 '17 at 20:51
  • Also no one has noticed the space in your column name so the below answers wont work . –  Jun 26 '17 at 20:54
  • Yes, bad in design in multiple ways. – AbraCadaver Jun 26 '17 at 20:58
  • I'm trying to learn @AbraCadaver, so if you could offer some constructive feedback, I would appreciate it. – Snoops Jun 26 '17 at 21:00
  • 1
    If you open a new question and give an outline of what you want to do in GENERAL, i.e. _save something that I can use to relate to some other thing later_ then you'll get some good suggestions. – AbraCadaver Jun 26 '17 at 21:04
  • @AbraCadaver I won't belabor the point but, when I've tried generic posts in the past, people get snippy for not providing specifics....can't win apparently. – Snoops Jun 26 '17 at 21:07
  • Thank you for pointing that out, @rtfm. How do I add the word "Test" to the end of the value SimplifyingFractions, though? – Snoops Jun 26 '17 at 21:17

1 Answers1

1

You'll run into the problem of max columns very quickly.

But try ADD COLUMN

EvgenyKolyakov
  • 3,310
  • 2
  • 21
  • 31
  • Thanks for your response. I don't quite follow though. Are you saying i should just change the line ` $db->query("ALTER TABLE answers ADD $LevelColumnAdder+"Test" VARCHAR( 255 ) NOT NULL");` to `$db->query("ALTER TABLE answers ADD COLUMN $LevelColumnAdder+"Test" VARCHAR( 255 ) NOT NULL");` ? – Snoops Jun 26 '17 at 21:11