INSERT data in more than one row at the same time, HELP!
Posted: Sat May 24, 2003 2:51 pm
Hi, i just started with mysql and i'm trying to insert the following variables into the database, if any one could give an example of how to insert data in more than one row at hte same time, i think that what i'm missing here.
Thx in advanced for your reply.
This file is saved as db.php
I GOT THIS ERROR
Parse error: parse error, unexpected T_ELSE in /Users/osx/Sites/mysql/db.php on line 6
Thx in advanced for your reply.
This file is saved as db.php
I GOT THIS ERROR
Parse error: parse error, unexpected T_ELSE in /Users/osx/Sites/mysql/db.php on line 6
Code: Select all
<?php
$username = "*****";
$password = "*****";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) or die ("Unable to connect to MySQL");
$selected = mysql_select_db("DB_Name",$dbh) or die ("Could not select DB_Name");
$data = array( array('$friend_last_name1', '$friend_name1', '$friend_email1', '$ip_address', '$date'),
array('$friend_last_name2', '$friend_name2', '$friend_email2', '$ip_address', '$date'),
array('$friend_last_name3', '$friend_name3', '$friend_email3', '$ip_address', '$date'));
$sth = $dbh->prepare("INSERT INTO table_name VALUES(Last_name,First_name,Email_address, ip_address, Date)");
foreach ($data as $row) {
$dbh->execute($sth, $row);
{
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
mysql_close($dbh);
?>