Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Records to a mysql database

Status
Not open for further replies.

Cirvam

Programmer
Nov 23, 1999
58
US
I'm new to php and was wondering how I can add a record to a mysql database.

Thanks

Erik
cirvam@netzero.net

Looking to learn more about Linux, Apache, PHP and others.
 
Hey there,

The mysql functions ( make this a piece of cake. Try this:

$link = mysql_connect('hostname','username','password');
/* You can use mysql_pconnect there with the same parameters if you want a persistant connection to the database */

mysql_select_db('dbname',$link);
/* dbname being of course, the name of your MySQL database */
$query = "INSERT INTO blah VALUES('blah','blah'";
/* or whatever SQL statement you had in mind */

if(!mysql_query($query,$link)) {
/* Handle the exception here, otherwise, you're done */
}

If you are making a select statement, then the mysql_query function return should be assigned to some variable (this return is what's known as a result id) and that variable can be used with functions such as mysql_result, mysql_fetch_row and mysql_fetch_array (my personal favorite :) Hope this helps. Later.

brendanc@icehouse.net
 
Thanks for the fast response :)

I'll try that... :)

Erik
cirvam@netzero.net

Looking to learn more about Linux, Apache, PHP and others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top