Попълване на полета за база данни

DirectX

Registered
defined( 'URL_HOME' ) &&
defined( 'MYSQL_DATABASE_HOST' ) &&
defined( 'MYSQL_DATABASE_USER' ) &&
defined( 'MYSQL_DATABASE_PASS' ) &&
defined( 'MYSQL_DATABASE_NAME' ) &&
defined( 'DB_PREFIX' ) )

кажете на всяко едно какво се попълва :)
 
defined( 'главният домейн на сайта' ) &&
defined( 'хоста (предимно е localhost но може и да е друг провериго)' ) &&
defined( 'usera на създадената база данни' ) &&
defined( 'паролата на базата данни' ) &&
defined( 'името на базата данни' ) &&
defined( 'префикс на таблиците (да кажем php) или каквото искаш' ) )
 
defined( 'името на базата данни' ) &&
и ще стане така:

defined( 'cs-sliven_admins' ) &&

така ли?
 
DirectX каза:
defined( 'името на базата данни' ) &&
и ще стане така:

defined( 'cs-sliven_admins' ) &&

така ли?

да ако базата данни е cs-sliven ,или cs-sliven е префикс ?
 
ето това съм направил до момента



това съм написъл за MqSql:

Код:
if ( !defined( 'DIR_ROOT' ) &&
	defined( 'uuuq.com' ) &&
	defined( '212.95.59.67' ) &&
	defined( 'cs-sliven_andrags' ) &&
	defined( '123456' ) &&
	defined( 'cs-sliven_skadate' ) &&
	defined( 'php' ) )


на ето този файл install.php ми дава грешка на 31 ред от този файл
31 ред е това"
$errors[] = 'Can't find "' . $sql_filename .'"';

Код:
<?php

error_reporting( E_ALL &~ E_NOTICE );

require_once( 'inc/inc.debug.php' );

$configs_filename = $_SESSION['dir_root'].'configs.php';

require_once( $configs_filename );

if ( !defined( 'DIR_ROOT' ) &&
	defined( 'uuuq.com' ) &&
	defined( '212.95.59.67' ) &&
	defined( 'cs-sliven_andrags' ) &&
	defined( '123456' ) &&
	defined( 'cs-sliven_skadate' ) &&
	defined( 'php' ) )
	{
		header( 'Location: index.php' );
		exit();
	}

function sqlImport( $sql_filename, $tables_prefix )
{
	global $errors;
	
	$fp = @fopen( $sql_filename, 'r' );
	
	if( !$fp )
	{
		$errors[] = 'Can't find "' . $sql_filename .'"';
		return false;
	}
	
	$line_num = 0;
	
	$_search = array
	(
		'CREATE TABLE `skadate_',
		'INSERT INTO `skadate_',
	);
	
	$_replace = array
	(
		'CREATE TABLE `'. $tables_prefix,
		'INSERT INTO `'. $tables_prefix,
	);
	
	// Set charset utf8 for mysql
	mysql_query( 'SET CHARACTER SET utf8' );
	
	while( $line = fgets( $fp, 10240 ) )
	{
		$line_num++;
		
		$line = trim( $line );
		
		if( $line[0] == '#' || $line[0] == '-' )
			continue;
		
		if( $line[strlen( $line )-1] == ';' )
		{
			$query .= $line;
		}
		else
		{
			$query .= $line;
			continue;
		}
		
		$result = mysql_query( str_replace( $_search, $_replace, $query ) );
		
		if( !$result )
		{
			$errors[] = 'SQL import error while executing line '. $line_num .' "'.$line.'".<br /><b>MySql error:</b> '.mysql_error().'</code>';
			return false;
		}
		
		$query = '';
	}

	fclose( $fp );
	
	return true;
}

function frontendDisplay( $page_title, $output, $javascript = '', $body_onload_js = '' )
{
	global $errors;
	
	?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
	<title>SkaDate Unity software installation - <?php print $page_title ?></title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
<style type="text/css">
body, table, input, textarea
{
	font-family: Tahoma;
	font-size: 11px;
	letter-spacing: 1px;
}

body
{
	background: #fff;
	color: #002747;
}

input
{
	margin: 0px;
	padding: 1px;
}

.error
{
	width: 700px;
	margin: 10px auto;
	border: 1px solid #b3babf;
	padding: 4px 6px;
	background: #af2020;
	color: #fff;
}

#page
{
	width: 700px;
	margin: 10px auto;
	padding: 4px 6px 20px 6px;
	background: #fff;
}

h2
{
	margin: 0;
	padding: 0px;
	text-align: center;
	font-family: monospace;
	font-size: 17px;
}

h3
{
	margin: 0 0 16px;
	padding: 0px;
	text-align: center;
	font-family: monospace;
	font-size: 11px;
	color: #2b4153;
}


table
{
	margin: auto;
	border: 1px solid #a7a7a7;
}

table thead td,
.wrong_permissions_cap
{
	border: 1px solid #b3babf;
	background-color: #424c5f;
	padding: 2px 4px;
	color: #f7f7f7;
	font-size: 15px;
}

table tbody td
{
	border: 1px solid #cfcfcf;
	padding: 3px 6px;
}

.left
{
	border-right: none;
	font-size: 10px;
	color: #535a5f;
	
}

.left b
{
	color: #122e5f;
	font-family: Verdana;
	letter-spacing: 0px;
}

table tfoot td,
.wrong_permissions_bottom
{
	border: 1px solid #d3d3b9;
	padding: 1px;
	background-color: #f7f7ec;
	text-align: right;
}

table tfoot td input,
.wrong_permissions_bottom input
{
	padding: 1px 3px;
	font-size: 10px;
	font-weight: bold;
}

.wrong_permissions
{
	width: 500px;
	margin: 0px auto;
	padding: 4px 0px;
}

.wrong_permissions_cap,
.wrong_permissions_bottom
{
	width: 500px;
	margin: 6px auto 0px auto;
}

code
{
	padding: 0px 2px;
	color: #1f1f1f;
}

.permissions
{
	padding: 0px 1px;
	color: #7f0000;
	font-size: 10px;
	font-weight: bold;
}

span.help
{
	border-bottom: 1px dotted #262d2f;
}

.help
{
	cursor: help;
}

</style>
	
	
	<?php
		if( $javascript )
			print "<script type="text/javascript">rn" .
					"</script>rn";
	?>
	
</head>

<body onload="<?php print $body_onload_js ?>">
<?php
	foreach( $errors as $_error )
	{
		print '<div class="error"><b>Error:</b> '. $_error .'</div>';
	}
?>
	<div id="page">
    <h3><a href="http://www.yagbu.net">www.yagbu.net - Release </a>!</h3>
	  <h2>SkaDate Unity</h2>
		<h3>software installation</h3>
		<?php print $output ?>
	</div>

</body>
</html>
<?php

	exit();

}





/* ---- Session start ---- */

session_start();

$errors = array();

/*session_destroy();
exit();*/


//print_arr( $_SESSION );








/* ------------------- Step 1 Files/Folders Permissions ------------------- */

if( $_POST['dir_root'] && $_POST['url_home'] )
{
	$_SESSION['_tmp_dir_root'] = $_POST['dir_root'];
	$_SESSION['_tmp_url_home'] = $_POST['url_home'];
	
	if( is_dir( $_SESSION['_tmp_dir_root'] . 'app/' ) && file_exists( $_SESSION['_tmp_dir_root'] . 'inc/class.component.php' ) )
	{
		$_SESSION['dir_root'] = $_SESSION['_tmp_dir_root'];
	}
	else
	{
		$errors[] = 'Incorrect home directory';
	}
	
	if( preg_match( '/^http://[a-z0-9_-./]{2,}/$/', $_SESSION['_tmp_url_home'] ) && @file_get_contents( $_SESSION['_tmp_url_home'] . 'install.php' ) )
	{
		$_SESSION['url_home'] = $_SESSION['_tmp_url_home'];
	}
	else
	{
		$errors[] = 'Incorrect script URL';
	}
}

if( $_POST['dir_root'] && !$_POST['url_home'] )
{
	$errors[] = 'Home derectory is not specified';
}
elseif( $_POST['url_home'] && !$_POST['dir_root'] )
{
	$errors[] = 'Home URL is not specified';
}

if( !$_SESSION['dir_root'] || !$_SESSION['url_home'] )
{
	$_rev_dir_root = substr( strchr( strrev( $_SERVER['SCRIPT_FILENAME'] ), '/' ), 1 );
	$dir_root = $_SESSION['_tmp_dir_root'] ? $_SESSION['_tmp_dir_root'] : strrev( $_rev_dir_root ) . '/';
	
	$output = '
<form method="POST">

	<table cellspacing="1">
		<thead>
			<tr>
				<td colspan="2">Home Directory & URL</td>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td class="left">
					<b>Home Directory</b><br />
					Specify the destination directory<br />
					of the script upload.
				</td>
				<td><input name="dir_root" type="text" size="46" value="'. $dir_root .'" /></td>
			</tr>
			<tr>
				<td class="left">
					<b>Home URL</b><br />
					Specify the full URL to the script.
				</td>
				<td><input id="url_home_input" name="url_home" type="text" size="46" value="'. $_SESSION['_tmp_url_home'] .'" /></td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="2"><input type="submit" value="Next »" /></td>
			</tr>
		</tfoot>
	</table>

</form>
';
	
	$js_code = '
function setDefaultUrl()
{
	var input = document.getElementById("url_home_input");
	
	if( !input.value )
		input.value = location.href.replace( //install.php$/, "/" );
}
';
	
	$onload_js = "setDefaultUrl()";
	
	frontendDisplay( 'Home Directory & URL', $output, $js_code, $onload_js );
}











/* ------------------- Step 2 Files/Folders Permissions ------------------- */

$need_777_permissions = array
(
	'_cache/',
	'images/',
	'media/',
);

foreach( $need_777_permissions as $_index => $_filename )
{
	if( is_writable( $_SESSION['dir_root'] . $_filename ) )
		unset( $need_777_permissions[$_index] );
}

/* --- Configs Filename --- */

// configs.php required above^

$has_undefined_constants = (
	!defined( 'DIR_ROOT' ) ||
	!defined( 'URL_HOME' ) ||
	!defined( 'MYSQL_DATABASE_HOST' ) ||
	!defined( 'MYSQL_DATABASE_USER' ) ||
	!defined( 'MYSQL_DATABASE_PASS' ) ||
	!defined( 'MYSQL_DATABASE_NAME' ) ||
	!defined( 'DB_PREFIX' )
	);

if( ( $has_undefined_constants && !is_writable( $configs_filename ) ) || !empty( $need_777_permissions ) )
{
	if( $has_undefined_constants && !is_writable( $configs_filename ) )
	{
		$output = '<li class="wrong_permissions">You need to set <code class="help" title="' .
			$configs_filename .'">configs.php</code> file <span title="Read Write Execute" class="help">rwx</span> ' .
				'permissions to <span class="permissions">777</span></li>';
	}
	
	foreach( $need_777_permissions as $_filename )
	{
		$output .= '<li class="wrong_permissions">You need to set <code class="help" title="' .
			$_SESSION['dir_root'] . $_filename . '">'.
				$_filename . '</code> directory <span title="Read Write Execute" class="help">rwx</span> ' .
					'permissions to <span class="permissions">777</b></li>';
	}
	
	$output = '
<div class="wrong_permissions_cap">Files permissions</div>
<ul>'. $output .'</ul>
<div class="wrong_permissions_bottom"><input type="button" value="Next »" onclick="location.href = location.href" /></div>';
	
	frontendDisplay( 'Files permissions', $output );
}









/* ------------------- Step 3 MySQL connection ------------------- */

if( $_POST['db_host'] || $_POST['db_user'] || $_POST['db_pass'] || $_POST['db_name'] || $_POST['db_prefix'] )
{
	$_SESSION['db_host'] = $_POST['db_host'];
	$_SESSION['db_user'] = $_POST['db_user'];
	$_SESSION['db_pass'] = $_POST['db_pass'];
	$_SESSION['db_name'] = $_POST['db_name'];
	$_SESSION['db_prefix'] = $_POST['db_prefix'];
}

/* ---- MySql connect ---- */
@$db_connect = mysql_connect( $_SESSION['db_host'], $_SESSION['db_user'], $_SESSION['db_pass'] );
$db_select = @mysql_select_db( $_SESSION['db_name'] );

if( !$db_connect || !$db_select || !$_SESSION['db_prefix'] )
{
	if( $_SESSION['db_host'] && !$db_connect )
		$errors[] = 'MySQL server connection failed. Please, check that you entered correct database connection info';
	elseif( $_SESSION['db_host'] && !$db_select )
		$errors[] = 'Wrong MySQL database selected. Make sure you entered correct database name';
	
	if( $_SESSION['db_host'] && !$_SESSION['db_prefix'] )
		$errors[] = 'Please enter database prefix';
	
	$db_host = $_SESSION['db_host'] ? $_SESSION['db_host'] : 'localhost';
	$db_prefix = $_SESSION['db_prefix'] ? $_SESSION['db_prefix'] : 'skadate_';
	
	
	$output = '
<form method="POST">

	<table cellspacing="1">
		<thead>
			<tr><td colspan="2">Database connection info</td></tr>
		</thead>
		<tbody>
			<tr>
				<td class="left">
					<b>Host name</b><br />
					Database host name
				</td>
				<td><input name="db_host" type="text" value="'. $db_host .'" /></td>
			</tr>
			<tr>
				<td class="left">
					<b>Username</b><br />
					Database user
				</td>
				<td><input name="db_user" type="text" value="'. $_SESSION['db_user'] .'" /></td>
			</tr>
			<tr>
				<td class="left">
					<b>Password</b><br />
					Database Password
				</td>
				<td><input name="db_pass" type="text" value="'. $_SESSION['db_pass'] .'" /></td>
			</tr>
			<tr>
				<td class="left">
					<b>Database name</b><br />
					Database name
				</td>
				<td><input name="db_name" type="text" value="'. $_SESSION['db_name'] .'" /></td>
			</tr>
			<tr>
				<td class="left">
					<b>Prefix</b><br />
					Database tables prefix
				</td>
				<td><input name="db_prefix" type="text" value="'. $db_prefix .'" /></td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="2"><input type="submit" value="Next »" /></td>
			</tr>
		</tfoot>
	</table>

</form>';
	
	frontendDisplay( 'Database connection', $output );
}



/* ---- SQL Import ---- */
if( !mysql_query( "SELECT `name` FROM `{$_SESSION['db_prefix']}config` LIMIT 1" ) )
{
	if( !sqlImport( $_SESSION['dir_root'] . 'skadate6unt.sql', $_SESSION['db_prefix'] ) )
		frontendDisplay( 'Database import', '' );
}

/* --- Configs Write --- */
if( $has_undefined_constants )
{
	$config_php_code = "<?php

define( 'DIR_ROOT', '{$_SESSION['dir_root']}' );

define( 'URL_HOME', '{$_SESSION['url_home']}' );

define( 'MYSQL_DATABASE_HOST', '{$_SESSION['db_host']}' );
define( 'MYSQL_DATABASE_USER', '{$_SESSION['db_user']}' );
define( 'MYSQL_DATABASE_PASS', '{$_SESSION['db_pass']}' );
define( 'MYSQL_DATABASE_NAME', '{$_SESSION['db_name']}' );
define( 'DB_PREFIX', '{$_SESSION['db_prefix']}' );
define( 'URL_SKADATE_HOME', 'http://www.skadate.com/' );

?>";
	
	$fp = fopen( $configs_filename, 'w' );
	
	fwrite( $fp, $config_php_code );
	
	fclose( $fp );
	
	header( 'Location: ' . $_SERVER['PHP_SELF'] );
	exit();
}










/* ------------ Step 4 Admin Panel Access ------------ */
$empty_access_field = false;

if( $_POST['admin_username'] || $_POST['admin_password'] || $_POST['admin_email'] )
{
	if( $_POST['admin_username'] )
		mysql_query( "UPDATE `". DB_PREFIX ."config` SET `value`='{$_POST['admin_username']}' WHERE `name`='admin_username'" );
	else
		$errors[] = 'Please choose admin login';
	
	if( !$_SESSION['admin_password_length'] )
	{
		if( $_POST['admin_password'] )
		{
			if( strlen( $_POST['admin_password'] ) < 4 )
			{
				$errors[] = 'The password must be more than four characters long';
			}
			elseif( $_POST['admin_password'] != $_POST['confirm_password'] )
			{
				$errors[] = 'Passwords don't match';
			}
			else
			{
				mysql_query( "UPDATE `". DB_PREFIX ."config` SET `value`='{$_POST['admin_password']}' WHERE `name`='admin_password'" );
				$_SESSION['admin_password_length'] = strlen( $_POST['admin_password'] );
			}
		}
		else
		{
			$errors[] = 'Please choose admin password';
		}
	}
	
	if( $_POST['admin_email'] )
	{
		if( !preg_match( '/^[a-z0-9._-]+@[a-z0-9._-]+.[a-z]{2,4}$/', $_POST['admin_email'] ) )
		{
			$errors[] = 'Email regular expression mismatch, make shure you intered a valid email';
		}
		else
		{
			mysql_query( "UPDATE `". DB_PREFIX ."config` SET `value`='{$_POST['admin_email']}' WHERE `name`='admin_email'" );
		}
	}
	else
	{
		$errors[] = 'Please specify admin email';
	}
}

$_query = "SELECT `name`,`value` FROM `". DB_PREFIX ."config`
		WHERE `name`='admin_username' OR `name`='admin_password' OR `name`='admin_email'";

$resource = mysql_query( $_query );

while( $_row = mysql_fetch_assoc( $resource ) )
{
	$admin_access_data[$_row['name']] = $_row['value'];
	
	if( !$_row['value'] )
		$empty_access_field = true;
}

if( $empty_access_field )
{
	
	$output = '
<form method="POST">
	<table cellspacing="1">
		<thead>
			<tr>
				<td colspan="2">Admin Pannel Access</td>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td class="left"><b>Login</b></td>
				<td><input name="admin_username" type="text" value="'.$admin_access_data['admin_username'].'" /></td>
			</tr>';
	
	if( !$_SESSION['admin_password_length'] )
	{
		$output .= '
			<tr>
				<td class="left"><b>Password</b></td>
				<td><input name="admin_password" type="password" value="" /></td>
			</tr>
			<tr>
				<td class="left"><b>Confirm password</b></td>
				<td><input name="confirm_password" type="password" value="" /></td>
			</tr>';
	}
	else
	{
		$output .= '
			<tr>
				<td class="left"><b>Password</b></td>
				<td><input type="text" value="'. str_repeat( '*', $_SESSION['admin_password_length'] ) .'" disabled /></td>
			</tr>
			<tr>
				<td class="left"><b>Confirm password</b></td>
				<td><input type="text" value="'. str_repeat( '*', $_SESSION['admin_password_length'] ) .'" disabled /></td>
			</tr>';
	}
	
	$admin_email = $_POST['admin_email'] ? $_POST['admin_email'] : $admin_access_data['admin_email'];
	
	$output .= '
			<tr>
				<td class="left"><b>Email</b></td>
				<td><input name="admin_email" type="text" value="'.$admin_email.'" /></td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="2"><input type="submit" value="Next »" /></td>
			</tr>
		</tfoot>
	</table>
</form>
';
	
	frontendDisplay( 'Admin Pannel Access', $output );
}






/* --------- Step 5 back Configs file permissions to 644 --------- */
if( is_writable( $configs_filename ) )
{
	$output = '
<div class="wrong_permissions_cap">Config File permissions</div>
<ul>
	<li class="wrong_permissions">Installation finished, you need to back <code class="help" title="' .
		$configs_filename .'">configs.php</code> file <span title="Read Write Execute" class="help">rwx</span> ' .
			'permissions to <span class="permissions">644</span></li>
</ul>
<div class="wrong_permissions_bottom">
	<input type="button" value="Finish" onclick="location.href = location.href" />
</div>';
	
	frontendDisplay( 'Config File permissions', $output );
}

header( 'Location: index.php' );



?>
става въпрос за система за запознанства - Skadate
 

Горе