cassisdesign
12-10-2008, 10:14 PM
I am trying to populate my two mysql tables that are already created using php. my two tables are 'logos' and 'files'.
Here is my php code:
<?php
$con = mysql_connect("localhost.localdomain","username","userpassword");
if(!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("jwfugate_db", $con);
/**
* Initial Database Setup
* run this only once per company, then comment it out or remove
*/
$company = 'KSM';
// $logos will be an array of the types of logos, and each type will be an array of the files for that type of logo
$logos['KSM - 1 Color'] = array('ksmcpa.eps','ksmcpa.jpg');
$logos['KSM - BW'] = array('ksmcpa_bw.eps','ksmcpa_bw.jpg'); // just for example purposes
// the thumbnails array will be associated to the logo type by using the same key value
$thumbnails['KSM - 1 Color'] = 'ksm_color.gif';
$thumbnails['KSM - BW'] = 'ksm_bw.gif';
// this is a more complex foreach loop
// it gives you access to the array keys -- foreach($array as $key=>$value)
foreach($logos as $type=>$files){
$sql = "INSERT INTO logos (company,title,filename) VALUES ($company,$type,{$thumbnails[$type]})";
mysql_query($sql);
$logos_id = mysql_insert_id(); // this returns the id of the last inserted item
foreach($files as $filename){
mysql_query("INSERT INTO files (logos_id,filename) VALUES ($logos_id,$filename)");
}
}
/**********/
mysql_close($con);
?>
Can anyone explain why my tables are not being populated via this php code?
Thanks!
Here is my php code:
<?php
$con = mysql_connect("localhost.localdomain","username","userpassword");
if(!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("jwfugate_db", $con);
/**
* Initial Database Setup
* run this only once per company, then comment it out or remove
*/
$company = 'KSM';
// $logos will be an array of the types of logos, and each type will be an array of the files for that type of logo
$logos['KSM - 1 Color'] = array('ksmcpa.eps','ksmcpa.jpg');
$logos['KSM - BW'] = array('ksmcpa_bw.eps','ksmcpa_bw.jpg'); // just for example purposes
// the thumbnails array will be associated to the logo type by using the same key value
$thumbnails['KSM - 1 Color'] = 'ksm_color.gif';
$thumbnails['KSM - BW'] = 'ksm_bw.gif';
// this is a more complex foreach loop
// it gives you access to the array keys -- foreach($array as $key=>$value)
foreach($logos as $type=>$files){
$sql = "INSERT INTO logos (company,title,filename) VALUES ($company,$type,{$thumbnails[$type]})";
mysql_query($sql);
$logos_id = mysql_insert_id(); // this returns the id of the last inserted item
foreach($files as $filename){
mysql_query("INSERT INTO files (logos_id,filename) VALUES ($logos_id,$filename)");
}
}
/**********/
mysql_close($con);
?>
Can anyone explain why my tables are not being populated via this php code?
Thanks!