Search Help Board

PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help

C# Help

?insert record
Date:???01-14-04 03:18

I would like to know the basic method of inserting data from a field into a database......
Lets say I have a First Name text box on a form, and someone enters a name, what code do I need to send that name to the relevant table in the database??

?Re: insert record
Date:???01-14-04 05:46

//insert page
//get user data

//validate first name -too many way here i'll leave it up to you

//open db connection
$conn=mysql_connection("localhost",$username, $password) or die ("can't connect to db because ".mysql_error());
$db=mysql_select_db($dbname) or die ("can't find db because ".mysql_error());

//create the sql -->ex below
/* text values ($var1, $var2) require single quotes around the var, numeric fields do not require quotes
field names (field1, field2) are required if not all fields are being entered

//$sql="insert into TableName ([field1, field2...fieldn] values

$sql="insert into TableName values ($'fname')";

//run the query
$result=mysql_query($sql) or die ("can't execute sql because ".mysql_error());

There more you can do, but this is the basics. Its best to get a good sql or php/mysql reference book to help you learn the basics.



Go to Top??|??Go to Topic??|??Threaded View??|??Search?
New Topic
?Reply To This Message
?Your Name:
?Your Email:
Email replies to this thread, to the address above.

Provided By