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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert values into a database using a file 1

Status
Not open for further replies.

mancroft

Programmer
Oct 26, 2002
267
GB
What I wish to do is insert values into a database using a file (insert.php).

1. Is the layout of the file (see below) the proper way to do it?

2. Once the file is created, what do I do?, just put it on the server and then run the url
<?
//dbuser
$usr = &quot;yyyyyyyy&quot;;
//dbpass
$pwd = &quot;xxxxxxxx&quot;;
//dbname
$db = &quot;zzzzzzzzzz&quot;;
//dbhost
$host = &quot;localhost&quot;;

// connect to the sql database
$link = mysql_connect($server, $user, $pass);
$db = mysql_select_db($database, $link);

&quot;insert into items values(0, 'Tony', 'Tony blah', 23.95)&quot;;
&quot;insert into items values(0, 'FI', 'FI blah',36.50)&quot;;

?>
 
U can make a seperate file for databases connection and include this into ur php script and run that script in the browser.
dbinc.php
Code:
<?
//dbuser
    $usr = &quot;yyyyyyyy&quot;;
    //dbpass
    $pwd = &quot;xxxxxxxx&quot;;
    //dbname
    $db = &quot;zzzzzzzzzz&quot;;
    //dbhost
    $host = &quot;localhost&quot;;

    // connect to the sql database  
    $link = mysql_connect($server, $user, $pass); 
    $db = mysql_select_db($database, $link); 
?>
insert.php
Code:
<?
include (&quot;/pathtodbinc.php/dbinc.php&quot;) ;
$sql1 = &quot;insert into items values(0, 'Tony', 'Tony blah', 23.95)&quot;; 
$result1 = mysql_query($sql1) ;
$sql2 =  &quot;insert into items values(0, 'FI', 'FI blah',36.50)&quot;; 
$result2 = mysql_query($sql2) ;
?>
Then to insert the values run that script from browser like





--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top