0

Hello & good afternoon,

I am developing an online product returns form which depending on the number of products the customer wants to return asks for the serial number of each one then i want to store each serial number in a MYSql database.

I just want to make sure i am creating the relevant number of columns the most efficient way & my code is as follows: -

if (isset($_POST['system_checkbox'])) 
{
  for ($i = 1; $i <= $qty; $i++)
  {
    mysqli_query($db, "ALTER TABLE credit_table ADD Serial_Number_$i VARCHAR(255)");
  } 
}

As you can see i am just using a basic for loop so each column is creating columns Serial_Number_1, Serial_Number_2, etc with $qty being the number of products being returned.

I also want to write the value of each serial number field from the form into the relevant columns which is where I become stuck.

Any advice would be appreciated.

Thanks in advance. Lee.

4
  • I dont think its a good idea to add columns freely like that Commented Aug 2, 2014 at 16:48
  • Dont do it that way use another table to hold this data Commented Aug 2, 2014 at 16:49
  • Okay, so i have two tables. Table one contains the customer info & tabe 2 contains details of the product being returned including the serial number(s). How would you propose I approach this differently? Commented Aug 2, 2014 at 18:13
  • Education, education, education. Read some tutorials on database design. Take a course. Employ someone who has a clue. Basically you dont have the knowledge or experience to do the job you are attempting. GET HELP. But this is not the place t get it. Commented Aug 2, 2014 at 19:09

1 Answer 1

1

Please read up on 3NF - http://en.wikipedia.org/wiki/Third_normal_form = You should not be altering databases except in unusual circumstances and then it is a one off event

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.