Jump to content

[SOLVED] Database & tables creating fine, but receiving error


BrianM

Recommended Posts

Well, for some reason my script throws an error like so - Table 'new_mps.mps_setup' doesn't exist - it hasn't always done this, and now it creates the database and tables and structure as well, but wont insert the post values like it used to. Does anyone see why my code is throwing an error. I'm not aware that I've even made any changes to it since the last time it was working fine. :|

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="styles/install.css" />
<title>Install</title>
<script type="text/javascript">
function check_input() {
    if (document.setup_.site_name.value == "") {
      document.setup_.site_name.focus();
      alert("Please enter your site name.");
      return false;
    }
    if (document.setup_.site_url.value == "") {
      document.setup_.site_url.focus();
      alert("Please enter your site URL.");
      return false;
    }
    if (document.setup_.administration_username.value == "") {
      document.setup_.administration_username.focus();
      alert("Please enter your administration username.");
      return false;
    }
if (document.setup_.administration_password.value == "") {
      document.setup_.administration_password.focus();
      alert("Please enter your administration password.");
      return false;
    }
if (document.setup_.mysql_server_name.value == "") {
  document.setup_.mysql_server_name.focus();
  alert("Please enter your MySQL server name.");
  return false;
}
if (document.setup_.mysql_username.value == "") {
  document.setup_.mysql_username.focus();
  alert("Please enter your MySQL username.");
  return false;
}
if (document.setup_.mysql_password.value == "") {
  document.setup_.mysql_password.focus();
  alert("Please enter your MySQL password.");
  return false;
}
if (document.setup_.mysql_database_name.value == "") {
  document.setup_.mysql_database_name.focus();
  alert("Please enter your MySQL database name.");
  return false;
}
if (document.setup_.mysql_table_prefix.value == "") {
  document.setup_.mysql_table_prefix.focus();
  alert("Please enter your MySQL table prefix.");
  return false;
}
    return true;
  }
</script>
</head>
<?php
if (isset($_POST['install'])) {

$site_name = $_POST['site_name'];
$site_url = $_POST['site_url'];
$administration_username = $_POST['administration_username'];
$administration_password = $_POST['administration_password'];
$mysql_server_name = $_POST['mysql_server_name'];
$mysql_username = $_POST['mysql_username'];
$mysql_password = $_POST['mysql_password'];
$mysql_database_name = $_POST['mysql_database_name'];
$mysql_table_prefix = $_POST['mysql_table_prefix'];

$mysql_connect = mysql_connect("$mysql_server_name", "$mysql_username", "$mysql_password") or die(mysql_error());

mysql_query("CREATE DATABASE $mysql_database_name", $mysql_connect) or die(mysql_error());

mysql_select_db("$mysql_database_name", $mysql_connect) or die(mysql_error());
$create_setup = "CREATE TABLE ".$mysql_table_prefix."site
(
site_name varchar(255) not null,
site_url varchar(255) not null,
mysql_server_name varchar(255) not null,
mysql_username varchar(255) not null,
mysql_password varchar(255) not null,
mysql_database_name varchar(255) not null,
mysql_table_prefix varchar(255) not null,
PRIMARY KEY(site_name)
)";
mysql_query($create_setup, $mysql_connect) or die(mysql_error());

$create_login = "CREATE TABLE ".$mysql_table_prefix."login
(
ID int(11) not null auto_increment,
username varchar(255) not null,
password varchar(255) not null,
access enum('administrator', 'employee') not null,
PRIMARY KEY(ID)
)";
mysql_query($create_login, $mysql_connect) or die(mysql_error());

$administration_password = md5($administration_password);
$mysql_password = md5($mysql_password);

mysql_query("INSERT INTO ".$mysql_table_prefix."setup (site_name, site_url, mysql_server_name, mysql_username, mysql_password, mysql_database_name, mysql_table_prefix)
VALUES ('".$site_name."', '".$site_url."', '".$mysql_server_name."', '".$mysql_username."', '".$mysql_password."', '".$mysql_database_name."', '".$mysql_table_prefix."')") or die(mysql_error());

mysql_query("INSERT INTO ".$mysql_table_prefix."login (username, password)
VALUES ('".$administration_username."', '".$administration_password."')") or die(mysql_error());

mysql_close($mysql_connect) or die(mysql_error());
}
?>
<body>
<form name="setup_" onsubmit="return check_input()" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<table id="install_main" border="0">
  <tr>
    <td class="install_title">Basic Setup</td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td class="install_type">Site name:<?php echo str_repeat(' ', 40); ?></td>
<td><input type="text" name="site_name" size="60" value="" />
<br /><div class="install_description">This is the name of your site, ie. "My Company Name".</div></td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td class="install_type">Site URL:</td>
<td><input type="text" name="site_url" size="60" value="http://<?php echo $_SERVER['HTTP_HOST']; echo dirname($_SERVER['PHP_SELF']) ?>" />
<br /><div class="install_description">This is the URL to your site. In most cases, you can leave the default value in this box alone - it is usually right.</div></td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td class="install_type">Administration username:</td>
<td><input type="text" name="administration_username" size="60" value="" />
<br /><div class="install_description">This is the administrative username you would like to log in with.</div></td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td class="install_type">Administration password:</td>
<td><input type="password" name="administration_password" size="60" value="" />
<br /><div class="install_description">This is the administrative password to use with your username you chose above.</div></td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
  	<td class="install_title">MySQL Setup</td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td class="install_type">MySQL server name:</td>
<td><input type="text" name="mysql_server_name" size="40" value="localhost" />
<br /><div class="install_description">In most cases, you can leave this value as is.</div></td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td class="install_type">MySQL username:</td>
<td><input type="text" name="mysql_username" size="40" value="" />
<br /><div class="install_description">Fill in the username you use to connect to your MySQL database here.</div></td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td class="install_type">MySQL password:</td>
<td><input type="password" name="mysql_password" size="40" value="" />
<br /><div class="install_description">Here, put the password you use to connect to your MySQL database.</div></td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td class="install_type">MySQL database name:</td>
<td><input type="text" name="mysql_database_name" size="40" value="" />
<br /><div class="install_description">This is the name of the database you want to store data in. Setup will create the database if it does not already exist.</div></td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td class="install_type">MySQL table prefix:</td>
<td><input type="text" name="mysql_table_prefix" size="40" value="" />
<br /><div class="install_description">The prefix for every table in the database, ie. "prefix_". Do not use the same prefix in the same database.</div></td>
  </tr>
  <tr>
    <td><?php echo str_repeat(' ', 1); ?></td>
  </tr>
  <tr>
    <td></td>
    <td><?php echo str_repeat(' ', 151); ?><input type="submit" name="install" value="Install" /></td>
  </tr>
</table>
</form>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.