Jump to content

ERROR: Could not query:Table (backup)


lucasd

Recommended Posts

Ive been given an existing website created in PHP which need to be connect to a mySQL database.

 

So far i have created the table and field in phpmyadmin and editing the setting.php file with the database information

when i test the site at www.5thgrader.com.au  i get the error "Could not query:Table '5thgrader_dbbackup._applicants_applicants' doesn't exist". The page is a registration form, from which all the fields are filled out and the infomation saved to a mySQL database for future reference.

 

I did not write this site and am reasonably new to PHP and SQL, from what i can see the backup database is causing the issue.

 

I have added the code from the functions.php and setting.php files. Feel free to login to phpmyadmin and check the database for yourself as im not sure where i im going wrong.

 

The server uses mySQL 5 and php 5.

 

the fuctions.php code as follows:

 

<?php
function textField($fieldName, $fieldTitle, $required = 0, $fieldValue = "") {
   $result = '';
   $result .= '<p><label for="';
   $result .= $fieldName . '-field"';
   $result .= '>';
   $result .= $fieldTitle;
   if ($required > 0) {
         $result .= '*';
      }
   $result .= '</label> <input id="';
   $result .= $fieldName . '-field" name="';
   $result .= $fieldName . '" title="';
   $result .= $fieldTitle . '" value="';
   $result .= $fieldValue . '" /></p>';
   
   return $result;
}

function textarea($fieldName, $fieldTitle, $required = 0, $fieldValue = "") {
   $result = '';
   $result .= '<p><label for="';
   $result .= $fieldName . '-field"';
   $result .= '>';
   $result .= $fieldTitle;
   if ($required > 0) {
         $result .= '*';
      }
   $result .= '</label> <textarea id="';
   $result .= $fieldName . '-field" name="';
   $result .= $fieldName . '" title="';
   $result .= $fieldTitle . '" ';
   $result .= 'rows="3" cols="20">';
   $result .= $fieldValue;
   $result .= '</textarea></p>';
   
   return $result;
}

function yesNo($fieldName, $fieldTitle, $required = 0, $fieldValue = "") {
   $result = '';
   $result .= '<p><label for="';
   $result .= $fieldName . '-field" ';
   $result .= '>';
   $result .= $fieldTitle;
   if ($required > 0) {
         $result .= '*';
      }
   $result .= '</label> <select name="';
   $result .= $fieldName . '" ';
   $result .= 'id="';
   $result .= $fieldName . '-field" ';   
   $result .= 'title="';
   $result .= $fieldTitle . '">';
   $result .= '<option value="" ';
   $result .= '>Select</option>';
   $result .= '<option value="Yes" ';
   if ($fieldValue == "Yes") {
      $result .= 'selected="selected" ';
   }
   $result .= '>Yes</option>';
   $result .= '<option value="No" ';
   if ($fieldValue == "No") {
      $result .= 'selected="selected" ';
   }
   $result .= '>No</option>';
   $result .= '</select></p>';
   
   return $result;
}

function connectToDb($bu = NULL) {
   global $db_server, $db_name, $db_username, $db_password, $db_tableprefix;
   global $dbbu_server, $dbbu_name, $dbbu_username, $dbbu_password;

//   if ($bu = "useBackup") {
      $link = mysql_connect($dbbu_server, $dbbu_username, $dbbu_password, 1);
//   }
//   else {
//      $link = mysql_connect($db_server, $db_username, $db_password, 1);
//   }

   if (!$link) {
      die('Could not connect to server: ' . mysql_error());
   }
   //echo 'Connected successfully';

//   if ($bu = "useBackup") {
      $db_selected = mysql_select_db($dbbu_name, $link);
//   }
//   else {
//      $db_selected = mysql_select_db($db_name, $link);
//   }
   
   




   if (!$db_selected) {
      die ('Could not select databse : ' . mysql_error());
   }

   return $link;
   
}

function disconnectDb ($linkID) {
   mysql_close($linkID);
}

function writeData ($formData) {
   global $db_server, $db_name, $db_username, $db_password, $db_tableprefix;

   $link = connectToDb();
   
   $sql = "";
   $sql .= "INSERT INTO " . $db_tableprefix . "_applicants ( ";
   $sql .= "firstname , surname , dob , phonebh , phoneah , email , ";
   $sql .= "street , suburb , state , pcode , occupation , hobbies , ";
   $sql .= "children , childrendets , resident , priorshow , priorshowdets , ";
   $sql .= "crime , crimedets , restorder , restorderdets , bank , bankdets , ";
   $sql .= "negative , negativedets , friends , auddate, education, terms, submitdate, contwhy ) ";
   $sql .= "VALUES ( ";
   $sql .= "'" . mysql_real_escape_string($formData["firstname"]) . "', ";
   $sql .= "'" . mysql_real_escape_string($formData["surname"]) . "', ";
   $sql .= "'" . mysql_real_escape_string($formData["dobyear"]) . "-"; // date of birth   <-- ######################################## THIS
   $sql .= mysql_real_escape_string($formData["dobmonth"]) . "-"; // date of birth   <-- ######################################## THIS
   $sql .= mysql_real_escape_string($formData["dobday"]) . "', "; // date of birth   <-- ######################################## THIS
   $sql .= "'" . mysql_real_escape_string($formData["phonebh"]) . "', ";
   $sql .= "'" . mysql_real_escape_string($formData["phoneah"]) . "', ";
   $sql .= "'" . mysql_real_escape_string($formData["email"]) . "', "; //email
   $sql .= "'" . mysql_real_escape_string($formData["address"]) . "', ";
   $sql .= "'" . mysql_real_escape_string($formData["suburb"]) . "', ";
   $sql .= "'" . mysql_real_escape_string($formData["state"]) . "', ";
   $sql .= "'" . mysql_real_escape_string($formData["pcode"]) . "', "; // post code
   $sql .= "'" . mysql_real_escape_string($formData["occupation"]) . "', ";
   $sql .= "'" . mysql_real_escape_string($formData["hobbies"]) . "' , ";
   $sql .= "'" . mysql_real_escape_string($formData["children"]) . "', "; //children
   $sql .= "'" . mysql_real_escape_string($formData["manychildren"]) . "' , "; // children dets
   $sql .= "'" . mysql_real_escape_string($formData["resident"]) . "', "; // resident
   $sql .= "'" . mysql_real_escape_string($formData["priorgameshow"]) . "', "; // prior show
   $sql .= "'" . mysql_real_escape_string($formData["whichshows"]) . "' , "; //prior show dets
   $sql .= "'" . mysql_real_escape_string($formData["crime"]) . "', "; //crime
   $sql .= "'" . mysql_real_escape_string($formData["crimedetails"]) . "' , "; // crime dets
   $sql .= "'" . mysql_real_escape_string($formData["restraining"]) . "', "; //rest order
   $sql .= "'" . mysql_real_escape_string($formData["restdetails"]) . "' , "; // rest order dets
   $sql .= "'" . mysql_real_escape_string($formData["bankruptcy"]) . "', "; // bank
   $sql .= "'" . mysql_real_escape_string($formData["bankdetails"]) . "' , "; //bank dets
   $sql .= "'" . mysql_real_escape_string($formData["negativeeffect"]) . "', "; //negative
   $sql .= "'" . mysql_real_escape_string($formData["negativedetails"]) . "' , "; // negative dets
   $sql .= "'" . mysql_real_escape_string($formData["friends"]) . "' , "; // friends
   $sql .= "'" . mysql_real_escape_string($formData["audition"]) . "' , "; // audition
   $sql .= "'" . mysql_real_escape_string($formData["education"]) . "', "; // education
   $sql .= "'" . mysql_real_escape_string($formData["terms"]) . "', "; // terms
   $sql .= "'" . mysql_real_escape_string(date("Y-m-d")) . "', "; // submit date
   $sql .= "'" . mysql_real_escape_string($formData["contwhy"]) . "'"; // contwhy
   $sql .= ")";
   
   // echo $sql;
   
   $result = mysql_query($sql, $link);
   if (!$result) {
      die('<br>Could not query:' . mysql_error());
   }

   $insertID = mysql_insert_id($link);
   // echo "<br>id: $insertID";
   
   disconnectDb($link);
   
/*   $link = connectToDb("useBackup"); //put data in backup database
   $result = mysql_query($sql, $link);
   if (!$result) {
      die('<br>Could not query:' . mysql_error());
   }
   disconnectDb($link);
*/   
}

function checkData ($formData) {
   $errors = "";
   
   if ($formData["firstname"] == "") {
      $errors .= "<p>Please enter your first name</p>";
   }
   
   if ($formData["surname"] == "") {
      $errors .= "<p>Please enter your surname</p>";
   }
         
   if ($formData["dobday"] == "") {
      $errors .= "<p>Please enter your full date of birth</p>";
   }
   elseif ($formData["dobyear"] == "") {
      $errors .= "<p>Please enter your full date of birth</p>";
   }
   
   if ($formData["phonebh"] == "") {
      $errors .= "<p>Please enter your business hours contact number</p>";
   }
   
   if ($formData["phoneah"] == "") {
      $errors .= "<p>Please enter your after hours contact number</p>";
   }
   
   if ($formData["address"] == "") {
      $errors .= "<p>Please enter your full home address</p>";
   }
   elseif ($formData["suburb"] == "") {
      $errors .= "<p>Please enter your full home address</p>";
   }
   elseif ($formData["pcode"] == "") {
      $errors .= "<p>Please enter your full home address</p>";
   }
   elseif (!is_numeric($formData["pcode"])) {
      $errors .= "<p>Please check the post code you entered</p>";
   }

   if ($formData["occupation"] == "") {
      $errors .= "<p>Please enter your Occupation</p>";
   }

   if ($formData["resident"] == "") {
      $errors .= "<p>Please enter if you are/are not an Australian Resident</p>";
   }
   
   if ($formData["education"] == "") {
      $errors .= "<p>Please tell us your highest level of education</p>";
   }
   
   if ($formData["priorgameshow"] == "") {
      $errors .= "<p>Please tell us if you've been on a game show previously</p>";
   }
   
   if (($formData["priorgameshow"] == "Yes") AND ($formData["whichshows"] == "")) {
      $errors .= "<p>Please enter which game shows you've been on previously</p>";
   }


   
   if ($formData["crime"] == "") {
      $errors .= "<p>Please tell us if you've ever been arrested, charged or convicted of a crime of any type</p>";
   }
   
   if (($formData["crime"] == "Yes") AND ($formData["crimedetails"] == "")) {
      $errors .= "<p>Please provide details of which crime and when</p>";
   }


   
   if ($formData["restraining"] == "") {
      $errors .= "<p>Please tell us if you've ever had a temporary restraining order issued against you</p>";
   }
   
   if (($formData["restraining"] == "Yes") AND ($formData["restdetails"] == "")) {
      $errors .= "<p>Please provide details the temporary restraining order issued against you</p>";
   }


   
   if ($formData["bankruptcy"] == "") {
      $errors .= "<p>Please tell us if you've ever filed for bankruptcy</p>";
   }
   
   if (($formData["bankruptcy"] == "Yes") AND ($formData["bankdetails"] == "")) {
      $errors .= "<p>Please provide details of your bankruptcy</p>";
   }


   
   if ($formData["negativeeffect"] == "") {
      $errors .= "<p>Please tell us if you've ever done or been involved in anything that could reflect negatively on either you or the series</p>";
   }
   
   if (($formData["negativeeffect"] == "Yes") AND ($formData["negativedetails"] == "")) {
      $errors .= "<p>Please provide details what you've been involved in that could reflect negatively on either you or the series</p>";
   }

   if ($formData["contwhy"] == "") {
      $errors .= "<p>Please tell why you want to be a game show contestant</p>";
   }
   

   
   if ($formData["audition"] == "") {
      $errors .= "<p>Please select city in which you'd prefer to audition</p>";
   }
   

   if ($formData["terms"] != "Yes") {
      $errors .= "<p>You must agree to the terms above to apply for the series</p>";
   }
   
   return $errors;

}

?>

 

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

 

And the setting.php code as follows:

 

<?php

putenv("TZ=Australia/Melbourne");


$db_name = "5thgrader_db01";
$dbbu_name = "5thgrader_dbbackup";
$db_username = "******";
$dbbu_username = "*******";
$db_password = "********";
$dbbu_password = $db_password;
$db_server = "mysql.****.com";
$dbbu_server = "mysql.*****com";
$db_tableprefix = "_applicants";

#Deal with magic quotes
function stripslashes_recursive($var) {
    return (is_array($var) ? array_map('stripslashes_recursive', $var) : stripslashes($var));
}
if (get_magic_quotes_gpc()) {
    $_GET = stripslashes_recursive($_GET);
    $_POST = stripslashes_recursive($_POST);
    $_COOKIE = stripslashes_recursive($_COOKIE);
}


?>

Link to comment
https://forums.phpfreaks.com/topic/151739-error-could-not-querytable-backup/
Share on other sites

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.