Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit 1fe1d71

Browse files
committed
create database config file only if connected to db
1 parent 900b84f commit 1fe1d71

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

install.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@
88
*/
99
require_once('functions.php');
1010
if(isset($_POST['host'])) {
11-
// create file 'dbinfo.php'
12-
$fp = fopen('dbinfo.php','w');
13-
$l1 = '$host="'.$_POST['host'].'";';
14-
$l2 = '$user="'.$_POST['username'].'";';
15-
$l3 = '$password="'.$_POST['password'].'";';
16-
$l4 = '$database="'.$_POST['name'].'";';
17-
$l5 = '$compilerhost="'.$_POST['chost'].'";';
18-
$l6 = '$compilerport='.$_POST['cport'].';';
19-
fwrite($fp, "<?php\n$l1\n$l2\n$l3\n$l4\n$l5\n$l6\n?>");
20-
fclose($fp);
21-
include('dbinfo.php');
11+
12+
2213
// connect to the MySQL server
23-
mysql_connect($host,$user,$password);
14+
$link=mysql_connect($_POST['host'],$_POST['username'],$_POST['password']);
15+
if (!$link) {
16+
die('Could not connect:' );
17+
}
18+
else {
19+
// create file 'dbinfo.php'
20+
$fp = fopen('dbinfo.php','w');
21+
$l1 = '$host="'.$_POST['host'].'";';
22+
$l2 = '$user="'.$_POST['username'].'";';
23+
$l3 = '$password="'.$_POST['password'].'";';
24+
$l4 = '$database="'.$_POST['name'].'";';
25+
$l5 = '$compilerhost="'.$_POST['chost'].'";';
26+
$l6 = '$compilerport='.$_POST['cport'].';';
27+
fwrite($fp, "<?php\n$l1\n$l2\n$l3\n$l4\n$l5\n$l6\n?>");
28+
fclose($fp);
29+
include('dbinfo.php');
2430
// create the database
2531
mysql_query("CREATE DATABASE $database");
2632
mysql_select_db($database) or die('Error connecting to database.');
@@ -81,6 +87,7 @@
8187
mysql_query($sql);
8288
header("Location: install.php?installed=1");
8389
}
90+
}
8491
?>
8592
<!DOCTYPE html>
8693
<html lang="en"><head>

0 commit comments

Comments
 (0)