Jump to content

Archived

This topic is now archived and is closed to further replies.

mburt

Adding Data to MySql with PHP

Recommended Posts

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

Share this post


Link to post
Share on other sites
One method is to use an INSERT query .... but I suspect there's more to your question than that.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.