Jump to content

Creating me a php file to create and insert table and data into mysql


big-dog1965

Recommended Posts

PLEASE HELP! Ive worked on this for days with no luck Ive posted ?s to errors and it either doesnt work or causes another errors. I know its asking a lot but could someone that knows this stuff write me the code to incorporate the create and insert into the php file. OR write the code in the php file that would read and write a .sgl file that has the create and insert data.

Heres the .PHP file it works fine the way it is. At set up tables ******* is where I added the extra table and data stuff and it bombs out so I went back with what works and that is what is here. the complete table stuff I need in there is below the php code

 

<?php


if(is_array($_POST)){
$HTTP_POST_VARS=$_POST;
}
if(is_array($_GET)){
$HTTP_GET_VARS=$_GET;
}
include(dirname(__FILE__)."/language.php");

$divFormat="<div style=\"text-align: center; font-weight: bold; font-family: verdana,arial; font-size: 15px;\">";
$backHome="$divFormat<a href=\"./\">".$Translation["goto start page"]."</a></div>";

// check this file's MD5 to make sure it wasn't called before
$prevMD5=@implode('', @file("./setup.md5"));
$thisMD5=md5(@implode('', @file("./setup.php")));
if($thisMD5==$prevMD5){
	echo "$divFormat ".$Translation["setup performed"]." ".date("r", filemtime("./setup.md5")).".<br><br></div>";
	echo "$divFormat<div style=\"font-size: 10px;\">".$Translation["delete md5"]."</div></div><br><br>";
	echo $backHome;
	exit;
}

// connect to the database
$dbServer=$HTTP_POST_VARS['dbServer'];
$dbUsername=$HTTP_POST_VARS['dbUsername'];
$dbPassword=$HTTP_POST_VARS['dbPassword'];
$dbDatabase=$HTTP_POST_VARS['dbDatabase'];
$noDB=0;
if(!@mysql_connect($dbServer, $dbUsername, $dbPassword)){
	$noDB=1;
}elseif(!@mysql_select_db($dbDatabase)){
	if(!@mysql_query("create database `$dbDatabase`")){
		$noDB=2;
	}else{
		if(!@mysql_select_db($dbDatabase)){
			$noDB=2;
		}
	}
}

// if no connection established, ask for connection data
if($noDB){
	if($dbServer!=''){
		echo $divFormat."<div style=\"color: red;\">".($noDB==1 ? $Translation["no db connection"] : str_replace("<DBName>", $dbDatabase, $Translation["no db name"]))."</div>"."</div>";
	}

	?>
	<form method="post" action="setup.php">
		<?php echo $divFormat; ?>
			<?php echo $Translation["provide connection data"]; ?>
			<center>
			<table bgcolor="#BFD5FF" style="border: solid silver 1px;" width="56%">
				<tr>
					<td align="right" width="35%"><?php echo $divFormat; ?><?php echo $Translation["mysql server"]; ?></div></td>
					<td>
					<input type="text" name="dbServer" size="20" value="localhost"></td>
					</tr>
				<tr>
					<td align="right" width="35%"><?php echo $divFormat; ?><?php echo $Translation["mysql username"]; ?></div></td>
					<td><input type="text" name="dbUsername" size="10"></td>
					</tr>
				<tr>
					<td align="right" width="35%"><?php echo $divFormat; ?><?php echo $Translation["mysql password"]; ?></div></td>
					<td><input type="password" name="dbPassword" size="10"></td>
					</tr>
				<tr>
					<td align="right" width="35%"><?php echo $divFormat; ?><?php echo $Translation["mysql db"]; ?></div></td>
					<td>
					<input type="text" name="dbDatabase" size="15"></td>
					</tr>
				<tr>
					<td align="right" width="35%"></td>
					<td><input type="submit" value="<?php echo $Translation["connect"]; ?>"></td>
					</tr>
				</table>
				</center>
		<p align="center">Delete this file through ftp after setup is complete 
		(setup.php)<br></p>
		<div style="font-size: 10px;"></div>
			</div>
		</form>
	<?php
	exit;
}else{
	// if connection is successful, save parameters into config.php
	if(!$fp=@fopen("./config.php", "w")){
		echo $divFormat."<div style=\"color: red;\">".$Translation["couldnt save config"]."</div></div><br>";
		echo $backHome;
		exit;
	}else{
		fwrite($fp, "<?php\n");
		fwrite($fp, "\t\$dbServer=\"$dbServer\";\n");
		fwrite($fp, "\t\$dbUsername=\"$dbUsername\";\n");
		fwrite($fp, "\t\$dbPassword=\"$dbPassword\";\n");
		fwrite($fp, "\t\$dbDatabase=\"$dbDatabase\";\n");
		fwrite($fp, "?>");
		fclose($fp);

	}
}

// set up tables *****************************
setupTable("ClanApps", "create table if not exists `ClanApps` ( `id` INT(10) unsigned not null auto_increment , primary key (`id`), `In_game_Name` VARCHAR(20) , `GSC_Login_Name` VARCHAR(20) , `Date_of_Birth` VARCHAR(10) , `Age` VARCHAR(2) , `State_Province` VARCHAR(25) , `Country` VARCHAR(20) , `Hear_About_TB` VARCHAR(255) , `Tactical_Realism` VARCHAR(255) , `Enjoyable_Gaming` VARCHAR(255) , `Join_Tactical_Brotherhood` VARCHAR(255) , `Former_CoD_Clan_1` VARCHAR(25) , `Clan_1_Duration` VARCHAR(25) , `Former_CoD_Clan_2` VARCHAR(25) , `Clan_2_Duration` VARCHAR(25) , `Former_CoD_Clan_3` VARCHAR(25) , `Clan_3_Duration` VARCHAR(25) , `Active_Presence` VARCHAR(3) , `EMail` VARCHAR(40) , `IP_Address` VARCHAR(20) , `Date_Submitted` DATE , `Approved` VARCHAR(3) )");

setupTable("login_table", "create table if not exists `login_table` ( `userid` INT(10) not null auto_increment , primary key (`userid`), `user_name` VARCHAR(20) , `user_pass` VARCHAR(50) , `user_level` VARCHAR(2) , `date` VARCHAR(11) , `user_email` VARCHAR(50) , `user_ip` VARCHAR(20) )");

mysql_query('INSERT INTO `user_Applications`.`login_table` (`userid`, `user_name`, `user_pass`, `user_level`, `date`, `user_email`, `user_ip`) VALUES (NULL, \'user\', \'21232f297a57a5a743894a0e4a801fc3\', \'4\', \'2009-02-21\', \'[email protected]\', \'\')');


// save MD5
if($fp=@fopen("./setup.md5", "w")){
	fwrite($fp, $thisMD5);
	fclose($fp);
}

// go to index
echo $backHome;

// ------------------------------------------

function setupTable($tableName, $createSQL='', $arrAlter=''){
	global $Translation;

	echo "<div style=\"padding: 5px; border-bottom:solid 1px silver; font-family: verdana, arial; font-size: 10px;\">";
	if($res=@mysql_query("select count(1) from `$tableName`")){
		if($row=@mysql_fetch_array($res)){
			echo str_replace("<TableName>", $tableName, str_replace("<NumRecords>", $row[0],$Translation["table exists"]));
			if(is_array($arrAlter)){
				echo '<br>';
				foreach($arrAlter as $alter){
					if($alter!=''){
						echo "$alter ... ";
						if(!@mysql_query($alter)){
							echo "<font color=red>".$Translation["failed"]."</font><br>";
							echo "<font color=red>".$Translation["mysql said"]." ".mysql_error()."</font><br>";
						}else{
							echo "<font color=green>".$Translation["ok"]."</font><br>";
						}
					}
				}
			}else{
				echo $Translation["table uptodate"];
			}
		}else{
			echo str_replace("<TableName>", $tableName, $Translation["couldnt count"]);
		}
	}else{
		echo str_replace("<TableName>", $tableName, $Translation["creating table"]);
		if(!@mysql_query($createSQL)){
			echo "<font color=red>".$Translation["failed"]."</font><br>";
			echo "<font color=red>".$Translation["mysql said"].mysql_error()."</font>";
		}else{
			echo "<font color=green>".$Translation["ok"]."</font>";
		}
	}

	echo "</div>";
}

?>

Here is the exported SQL code from a .SQL file that I need to incororated into the ,PHP file or read and write into the database from the .PHP file

-- Table structure for table 'ClanApps'
--

CREATE TABLE IF NOT EXISTS ClanApps (
  id int(10) unsigned NOT NULL auto_increment,
  In_game_Name varchar(20) default NULL,
  GSC_Login_Name varchar(20) default NULL,
  Date_of_Birth varchar(10) default NULL,
  Age varchar(2) default NULL,
  State_Province varchar(25) default NULL,
  Country varchar(20) default NULL,
  Hear_About_TB varchar(255) default NULL,
  Tactical_Realism varchar(255) default NULL,
  Enjoyable_Gaming varchar(255) default NULL,
  Join_Tactical_Brotherhood varchar(255) default NULL,
  Former_CoD_Clan_1 varchar(25) default NULL,
  Clan_1_Duration varchar(25) default NULL,
  Former_CoD_Clan_2 varchar(25) default NULL,
  Clan_2_Duration varchar(25) default NULL,
  Former_CoD_Clan_3 varchar(25) default NULL,
  Clan_3_Duration varchar(25) default NULL,
  Active_Presence varchar(3) default NULL,
  EMail varchar(40) default NULL,
  IP_Address varchar(20) default NULL,
  Date_Submitted date default NULL,
  Approved varchar(3) default NULL,
  PRIMARY KEY  (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table 'ClanApps'
--


-- --------------------------------------------------------

--
-- Table structure for table 'login_table'
--

CREATE TABLE IF NOT EXISTS login_table (
  userid int(10) NOT NULL auto_increment,
  user_name varchar(20) default NULL,
  user_pass varchar(50) default NULL,
  user_level varchar(2) default NULL,
  `date` varchar(11) default NULL,
  user_email varchar(50) default NULL,
  user_ip varchar(20) default NULL,
  PRIMARY KEY  (userid)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table 'login_table'
--

INSERT INTO login_table (userid, user_name, user_pass, user_level, date, user_email, user_ip) VALUES
(1, 'user', '21232f297a57a5a743894a0e4a801fc3', '4', '2009-02-21', '[email protected]', '');

-- --------------------------------------------------------

--
-- Table structure for table 'memb_adminsessions'
--

CREATE TABLE IF NOT EXISTS memb_adminsessions (
  session_id varchar(255) NOT NULL,
  session_date datetime NOT NULL,
  PRIMARY KEY  (session_id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='List of Membership v1.0 admin sessions';

--
-- Dumping data for table 'memb_adminsessions'
--


-- --------------------------------------------------------

--
-- Table structure for table 'memb_config'
--

CREATE TABLE IF NOT EXISTS memb_config (
  config_name varchar(255) NOT NULL,
  config_value text NOT NULL,
  PRIMARY KEY  (config_name)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='List of Membership v1.0 config values';

--
-- Dumping data for table 'memb_config'
--

INSERT INTO memb_config (config_name, config_value) VALUES
('CF_CAPTHCA', 'TEXT'),
('CF_BACKGROUNDS', 'extras/background_1.png,extras/background_2.png,extras/background_3.png'),
('CF_FONTS', 'extras/COOPBLA.TTF,extras/TIMES.TTF'),
('CF_SIZE', '18'),
('CF_QUESTIONFILE', 'extras/questions.txt'),
('CF_E_REG', '1'),
('CF_USER_LIMIT', '0'),
('CF_E_VER', '1'),
('CF_E_DEL', '1'),
('CF_ENCDEC', 'klJM()*Ulkopi324p'),
('CF_LENGH', '5'),
('CF_ADMINNAME', 'admin'),
('CF_ADMINPASSWORD', 'admin2008'),
('CF_SITENAME', 'MemberShip'),
('CF_SITEEMAIL', '[email protected]'),
('CF_SANDBOX', '2'),
('CF_LOG_TYPE', '1'),
('CF_PAYPALID', '[email protected]'),
('CF_2COID', '107303'),
('CF_REGISTEREMAIL_S', 'Please verify your email @ $SITE_NAME'),
('CF_REGISTEREMAIL_B', '<b>Hello,</b></span><br /><br />\r\n<span align="justify"><b>Thank you for registering at $SITE_NAME.</b></span><br /><br />\r\n<span align="justify"><b>Your login password is: $PASS_WORD.</b></span><br /><br />\r\n/IFVERIFICATION/\r\n<span align="justify"><b>However, before you can start using your account, we need to confirm this email.</b></span><br /><br />\r\n<span align="justify"><b>Please visit this link to activate your account <a href="$ACT_LINK" target="_blank">$ACT_LINK</a></font></b></span><br /><br />\r\n/IFVERIFICATION/\r\n<span align="justify"><b>Thank you, </b></span>'),
('CF_FORGOTEMAIL_S', 'Please password @ $SITE_NAME'),
('CF_FORGOTEMAIL_B', '<b>Hello,</b></span><br /><br />\r\n<span align="justify"><b>Your login password is: $PASS_WORD.</b></span><br /><br />\r\n<span align="justify"><b>Thank you, </b></span>'),
('CF_CHANGEEMAIL_S', 'Please confirm email change @ $SITE_NAME'),
('CF_CHANGEEMAIL_B', '<b>Hello $USER_NAME,</b></span><br /><br />\r\n<span align="justify"><b>You requested that your account, currently using this email to be changed to: $NEW_EMAIL.</b></span><br /><br />\r\n<span align="justify"><b>To confirm such action, you need to click here: <a href="$ACT_LINK">$ACT_LINK</a>.</b></span><br /><br />\r\n<span align="justify"><b>Thank you, </b></span>'),
('CF_URLINC', 'http://localhost/ap/work/Membership/'),
('CF_SANDBOX2', '2');

-- --------------------------------------------------------

--
-- Table structure for table 'memb_customfds'
--

CREATE TABLE IF NOT EXISTS memb_customfds (
  field_id bigint(20) NOT NULL auto_increment,
  field_name varchar(255) NOT NULL,
  is_required tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (field_id)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COMMENT='List of Membership v1.0 custom fields' AUTO_INCREMENT=3 ;

--
-- Dumping data for table 'memb_customfds'
--

INSERT INTO memb_customfds (field_id, field_name, is_required) VALUES
(1, 'Gender', 1),
(2, 'Age', 0);

-- --------------------------------------------------------

--
-- Table structure for table 'memb_memberships'
--

CREATE TABLE IF NOT EXISTS memb_memberships (
  membership_id bigint(20) NOT NULL auto_increment,
  membership_title varchar(255) NOT NULL,
  membership_desc text NOT NULL,
  membership_file varchar(255) NOT NULL,
  membership_free tinyint(1) NOT NULL default '1',
  membership_public tinyint(1) NOT NULL default '1',
  PRIMARY KEY  (membership_id)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COMMENT='list of all memberships' AUTO_INCREMENT=3 ;

--
-- Dumping data for table 'memb_memberships'
--

INSERT INTO memb_memberships (membership_id, membership_title, membership_desc, membership_file, membership_free, membership_public) VALUES
(1, 'Free', 'Free', '/kunden/homepages/28/d243998695/htdocs/Demos/Membership/extras/.free.fdaccess', 1, 1),
(2, 'Super', 'Access to all sections', '/kunden/homepages/28/d243998695/htdocs/Demos/Membership/extras/.super.fdaccess', 2, 1);

-- --------------------------------------------------------

--
-- Table structure for table 'memb_memberships_rates'
--

CREATE TABLE IF NOT EXISTS memb_memberships_rates (
  rate_id int(11) NOT NULL auto_increment,
  membership_id bigint(20) NOT NULL,
  rate_title varchar(255) NOT NULL,
  rate_desc text NOT NULL,
  rate_amount varchar(255) NOT NULL,
  rate_term bigint(255) NOT NULL,
  rate_term_c varchar(1) NOT NULL,
  rate_automatic tinyint(1) NOT NULL default '1',
  2checkout_PID varchar(255) NOT NULL,
  PRIMARY KEY  (rate_id)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COMMENT='List of all rates for memberships' AUTO_INCREMENT=3 ;

--
-- Dumping data for table 'memb_memberships_rates'
--

INSERT INTO memb_memberships_rates (rate_id, membership_id, rate_title, rate_desc, rate_amount, rate_term, rate_term_c, rate_automatic, 2checkout_PID) VALUES
(1, 1, 'test', 'test', '33.00', 1, 'W', 1, '5'),
(2, 2, 'Test1', 'Unlimited', '99.99', 1, 'W', 1, '5');

-- --------------------------------------------------------

--
-- Table structure for table 'memb_payments'
--

CREATE TABLE IF NOT EXISTS memb_payments (
  payment_id bigint(20) NOT NULL auto_increment,
  membership_id bigint(20) NOT NULL,
  user_id bigint(20) NOT NULL,
  rate_id bigint(20) NOT NULL,
  rate_amount varchar(255) NOT NULL,
  payment_date datetime NOT NULL,
  system_id bigint(20) NOT NULL,
  PRIMARY KEY  (payment_id)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COMMENT='List of payments' AUTO_INCREMENT=2 ;

--
-- Dumping data for table 'memb_payments'
--

INSERT INTO memb_payments (payment_id, membership_id, user_id, rate_id, rate_amount, payment_date, system_id) VALUES
(1, 2, 1, 3, '33', '2008-10-18 00:00:00', 1);

-- --------------------------------------------------------

--
-- Table structure for table 'memb_paysystem'
--

CREATE TABLE IF NOT EXISTS memb_paysystem (
  system_id bigint(20) NOT NULL auto_increment,
  system_title varchar(255) NOT NULL,
  system_desc text NOT NULL,
  PRIMARY KEY  (system_id)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COMMENT='List of all payment systems' AUTO_INCREMENT=3 ;

--
-- Dumping data for table 'memb_paysystem'
--

INSERT INTO memb_paysystem (system_id, system_title, system_desc) VALUES
(1, 'Paypal', 'Paypal is a secure method of payment'),
(2, '2CheckOut', '2Checkout is a secure form of online payment');

-- --------------------------------------------------------

--
-- Table structure for table 'memb_userlist'
--

CREATE TABLE IF NOT EXISTS memb_userlist (
  user_id bigint(20) NOT NULL auto_increment,
  membership_id bigint(20) NOT NULL,
  user_email varchar(255) NOT NULL,
  user_name varchar(255) NOT NULL,
  user_password varchar(255) NOT NULL,
  user_status varchar(50) NOT NULL,
  register_date datetime NOT NULL,
  last_ip varchar(255) NOT NULL,
  last_access datetime NOT NULL,
  allow_delete tinyint(1) NOT NULL,
  user_in_list tinyint(1) NOT NULL,
  custom_fields longtext NOT NULL,
  PRIMARY KEY  (user_id)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COMMENT='List of Membership v1.0 users' AUTO_INCREMENT=3 ;

--
-- Dumping data for table 'memb_userlist'
--

INSERT INTO memb_userlist (user_id, membership_id, user_email, user_name, user_password, user_status, register_date, last_ip, last_access, allow_delete, user_in_list, custom_fields) VALUES
(2, 1, '[email protected]', 'test', 'test', '1', '0000-00-00 00:00:00', '', '0000-00-00 00:00:00', 1, 1, '[6]{+|%|+}[tt]\n[5]{+|%|+}[tt]\n'),
(1, 1, '[email protected]', 'Test', 'test', '1', '0000-00-00 00:00:00', '', '0000-00-00 00:00:00', 1, 1, '[6]{+|%|+}[]\n[5]{+|%|+}[]\n');

-- --------------------------------------------------------

--
-- Table structure for table 'memb_usersessions'
--

CREATE TABLE IF NOT EXISTS memb_usersessions (
  session_id varchar(255) NOT NULL,
  user_id bigint(20) NOT NULL,
  session_date datetime NOT NULL,
  PRIMARY KEY  (session_id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='List of Membership v1.0 user sessions';

--
-- Dumping data for table 'memb_usersessions'
--

Thank you so much

Site Rules

 

Don't ask someone to write or re-write a script for you, unless you are posting a message to the Freelancing Forum. The forums are not the place to request XYZ script. This is a community of people learning PHP, and not a script location service. Try searching SourceForge, PHP Classes, HotScripts, or Google.

 

Please read the rules of the forum and follow them.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.