Database Install
Posted: Thu Dec 02, 2010 1:37 pm
I'm working on a project that allows a user to type in the web server info and allow then to install my guestbook on their server. Of course I test it at home, where I use localhost, and all is well the app works amazingly, as for others on a public sever, their server's info is needed such as the server name, database username, etc. How do I set the connection to allow their input. I'll paste the codes bellow:
Database connection
Configuration
Install
I need to make all this to allow users to enter the host name, username and password as well as the database being used to insert the tables in.
Database connection
Code: Select all
<?php
//check if this info exists
$connect = mysql_connect("localhost","root","");
$dbconn = mysql_select_db("jae_guestbook");
$queryget = mysql_query("SELECT * FROM userposts ORDER BY id ASC");
?>
Code: Select all
<?php
//if info in con.php does not exist, run configuration
include("../book/conn.php");
$checkdb = $dbconn;
if($checkdb){
echo "<meta http-equiv='refresh' content='0.0001;index.html'>";
} else {
echo "<h1>Guestbook Configuration</h1>\n";
echo "<p>Before we can continue with the installation, we need a bit of info.<br />Please supply us with the following information so we can install your guestbook as soon as possible.</p>";
}
$style = "font-size:8pt;";
if(isset($_REQUEST['submit'])){
$host = $_REQUEST['host'];
$dbname = $_REQUEST['dbname'];
$user = $_REQUEST['user'];
$pass = $_REQUEST['pass'];
$connect;
if($host){
echo "good";
} else {
echo "bad";
}
}
echo "<form action='conf.php' method='REQUEST'>
<table>
<tr>
<td>
Server/Host:
</td>
<td>
<input type='text' name='host' />
" ?> <a href='#' onmouseover="document.hosthelp.src='../images/host.gif'" onmouseout="document.hosthelp.src='../images/help.gif'"><img src='../images/help.gif' alt="What's This?" name="hosthelp" /></a>
<?php echo"
</td>
</tr>
<tr>
<td>
Database Name:
</td>
<td>
<input type='text' name='dbname' />
"?>
<a href="#" onmouseover="document.dbhelp.src='../images/db.gif'" onmouseout="document.dbhelp.src='../images/help.gif'"><img src="../images/help.gif" name="dbhelp" alt="What's This?" /></a>
<?php echo"
</td>
</tr>
<tr>
<td>
Login Username:
</td>
<td>
<input type='text' name='user' />
"?>
<a href="#" onmouseover="document.usrhlp.src='../images/user.gif'" onmouseout="document.usrhlp.src='../images/help.gif'"><img src="../images/help.gif" name="usrhlp" alt="What's This?" /></a>
<?php echo"
</td>
</tr>
<tr>
<td>
Login Password:
</td>
<td>
<input type='password' name='pass' />
<span style='$style'>Keep blank if no password</span>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type='submit' name='submit' value='Install' />
<input type='reset' value='Reset' /><br />
<span style='$style'>Please note, you must have the database created before continuing with the installation.</span>
</td>
</tr>
</table>
</form>";
?>
Code: Select all
<?php
//when info is entered in, run this SQL code on their sql server
include("../book/conn.php");
if($checkdb){
echo "<meta http-equiv='refresh' content='0.001;success.php'>";
} else {
$installtable = mysql_query("CREATE TABLE `jae_guestbook`.`userposts` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 64 ) NOT NULL ,
`email` VARCHAR( 64 ) NOT NULL ,
`message` TEXT NOT NULL ,
`date` DATE NOT NULL ,
`time` TIME NOT NULL
) ENGINE = MYISAM
");
}
echo "<meta http-equiv='refresh' content='0.001;success.php'>";
?>