Jump to content


Adding Data to MySql with PHP

  • Please log in to reply
2 replies to this topic

#1 mburt

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 August 2006 - 02:08 PM

I have a very simple question:
How do I add data to my MySql database?

#2 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 August 2006 - 02:14 PM

One method is to use an INSERT query .... but I suspect there's more to your question than that.
Legend has it that reading the manual never killed anyone.
My site

#3 mr. big

mr. big
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 28 August 2006 - 03:09 PM

It's not really a simple question at all.

Basically, what I do is to create a html form with one input section for each column, the input type being appropriate, i.e. radio buttons for boolean or a small set, checkboxes for enum, text or textbox for text, etc.  I use method $_POST and action = the same file name, although you could put the php in a separate file and that would be the action.  The name of each input will become a value in the POST array, so name="color" in the form input will become $_POST['color'].

Above it in the same file I put a php section that takes the POST data, gives it easier variable names, then does a MySQL INSERT query.  E.g., $c = $_POST['color'], then "INSERT INTO elephants (color, favorite_song) VALUES ('$c','$fs")";

Ullman's book "PHP and MySQL" has a good section on this.
"Every monkey thinks its children are beautiful."

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users