Click to See Complete Forum and Search --> : Can I insert from php into MySQL?


Mike B Best
08-25-2001, 12:13 PM
Hi,

I am very new to using MySQL. I was wondering how/if you can insert a record into a MySQL table. I guess you must be able to but after trauling through the php docs I can't find anything.

Thanks

Mike :confused:

element-x
08-26-2001, 04:29 PM
<?php
/* Connect to MySQL server */
$link = mysql_connect ("localhost", "username", "password") or die ("Could not connect");
/* Make MySQL Query */
$query = "INSERT INTO db (field1,field2) VALUES ('field1_value','field2_value')";
$result = mysql_query ($query) or die("Invalid Query");
/* Close MySQL link */
mysql_close ($link);
?>


This is VERY basic, but I think this is how you would approach your problem.

Mike B Best
08-26-2001, 04:44 PM
That's great, just what I needed! :D