Jump to content

skygremlin

Members
  • Posts

    41
  • Joined

  • Last visited

Everything posted by skygremlin

  1. Thanx mac_gyver. I thought about putting the full page content in the DB and using one page file for display, but wasn't sure if putting html in the DB was the right path to take. Sounds like in this instance not a bad choice. thank you
  2. nah that didn't work, and that removes the css to my root/home.php...
  3. Folder structure with some additional data: root/css/main.css Inside the css file .header-news-events { background-image: url("../img/sub-img/sub-news.jpg"); } root/img/sub-img root/includes/header.php ​Inside the Header File <link rel="stylesheet" href="css/main.css"> <script type="text/javascript" src="js/main.js"></script> root/js/
  4. I also have url linking in my css file to yet another folder location.. From the css file that's ../img/sub-img/... Could that be messing with something? I thought the url links started at the css file location though..
  5. I've also tried this with same result.... $docRoot = ($_SERVER['DOCUMENT_ROOT']); echo'<script type="text/javascript">window.alert("Doc Root: '.$docRoot.'")</script>'; $headerLink = ($docRoot . "/css/header.php"); echo'<script type="text/javascript">window.alert("Another Link to Header: '.$headerLink.'")</script>'; include($headerLink); I think it's something more fundamental that I'm missing......
  6. Do you mean like this? include("/../includes/header.php"); If I do that I loose my header..
  7. I’m trying to organize a site and am missing something basic with linking my css.. Right now all the pages are in the root folder. I am using a template that includes a header and footer, only changing the body on each page. The header file contains links to the css and js files. I want to move all my news and events to a sub folder (newsEvents), as I expect a large number of these pages. For example: Folder structure: root/css/main.css root/includes/header.php root/newsEvents.php root/newsEvents/2014-04-29_eventPosting.php Working Page: root/newsEvents.php — loads css and javascript fine Inside of this page is the below line include(includes/header.php); Not working Page: root/newsEvents/2014-04-29_eventPosting.php — Does not load the css or the javascript Inside of this page is the below line include(../includes/header.php); I’m looking at the Debugger in FF, and I’ll see the CSS file listed for each page, but it shows 0 rules on the one not working. On the working page it shows 198 rules. I thought changing the includes path would be enough to load the header, which would included path’s to the css and js files.. But again, I’m missing something basic.. I’m using MAMP for my testing. If that makes a difference.. thank you
  8. Thanx mac_gyver and trq.. @mac_gyver I'm trying your suggestions and so far no luck... I'll play around some more and see if I can figure out what I'm doing wrong.. I'm sure it's something basic, I just need to do some more looking / research. @trq thank you. I think we're on the same page.. Hopefully just a poor choice of words on my part.. That being said what you posted helped me look at things from another angle. thanx guys
  9. I've fixed the undefined variable in the past with using !empty like below.. But for some reason If I use the below code it's still posting those errors. And my query doesn't seem to be working either... function __construct($config){ if(isset($config['host'])){ if(!empty($config['host'])){ $this->host = ($config['host']); echo'<script type="text/javascript">window.alert("Host is: '.$this->host.'")</script>'; } } if(isset($config['dbname'])){ if(!empty($config['dbname'])){ $this->dbname = ($config['dbname']); echo'<script type="text/javascript">window.alert("DBname is: '.$this->dbname.'")</script>'; } } if(isset($config['username'])){ if(!empty($config['username'])){ $this->username = ($config['username']); echo'<script type="text/javascript">window.alert("UserName is: '.$this->username.'")</script>'; } } if(isset($config['password'])){ if(!empty($config['password'])){ $this->password = ($config['password']); echo'<script type="text/javascript">window.alert("Password is: '.$this->password.'")</script>'; } } $this->open_connection(); }
  10. hmmm I made a couple changes with new results. I think I'm understanding what you meant.. Index.php: /** * If connected to DB load page * Else echo not connected */ if (isset($database)){ //echo "Database opened"; /** * Run query to verify working. */ $customers = cust_list($database->dbConn); echo "<pre>"; print_r($customers); echo "</pre>"; } else { echo "Database not opened"; } MySQL Database Class: class MySQLDatabase { /** * MySql Connect to DB */ private $host; private $dbname; private $username; private $password; public $dbConn; function __construct($config){ $this->host = ($config['host']); $this->dbname = ($config['dbname']); $this->username = ($config['username']); $this->password = ($config['password']); $this->open_connection(); } private function open_connection(){ try{ //$this->connection = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); $this->dbConn = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); echo '<script type="text/javascript">window.alert("Function: '.__FUNCTION__.' Line: '.__LINE__.'")</script>'; }catch(PDOException $e){ echo 'ERROR Inside the open_connection funtion: ' . $e->getMessage(); } } } /** * Create object */ $database = new MySQLDatabase($config); New Errors: Notice: Undefined variable: host in /Users/aaronjk/localhost/base_sites/php_base/includes/db_conn/MYSQL_database.php on line 29 Notice: Undefined variable: dbname in /Users/aaronjk/localhost/base_sites/php_base/includes/db_conn/MYSQL_database.php on line 29 Notice: Undefined variable: username in /Users/aaronjk/localhost/base_sites/php_base/includes/db_conn/MYSQL_database.php on line 29 Notice: Undefined variable: password in /Users/aaronjk/localhost/base_sites/php_base/includes/db_conn/MYSQL_database.php on line 29 Array ( [host] => localhost [username] => root [password] => root [dbname] => portal_db ) Array()
  11. I’m moving my code from Procedural to OOP and am having an issue trying to run a basic query. Looks like the connection to the DB is made, but I must not be fully understanding Objects / scope of Objects yet.. I’m trying keep it simple so I can test this out and understand it before updating my code. My instal thoughts are: 1. Get OOP class set up for DB Connection. MySQL first as that’s what I’m using now. Then config MSSQL and Oracle classes for easy integration. 2. Get simple queries working using a basic function file with PDO (Like current code). 3. Convert my function files to classes. I’ve separated my code to 3 function files (categories) for some organization. The files aren’t huge, but they do range from 150 lines to just over 1000. Below is the code I’m testing with. Pretty simple and I hope straight forward. I’ve also tried sending in $dbConn as a variable versus have it as a global variable in the function.. I’ve read that’s the better way. But if anybody has thoughts on that too I would love to hear opinions / recommendations. thanx Index.php - testing page: /** * Start Includes sections */ require_once("../includes/db_conn/MYSQL_database.php"); require_once("../includes/functions.php"); /** * End Includes sections */ /** * Check DB Connection */ if (isset($config)){ echo"<pre>"; print_r($config); echo"<pre>"; }else{ echo'<script type="text/javascript">window.alert("config not set")</script>'; } echo"<hr>"; //if (isset($database)){echo "Database opened"; } else {echo "Database not opened";} /** * If connected to DB load page * Else echo not connected */ if (isset($database)){ //echo "Database opened"; /** * Run query to verify working. */ $customers = cust_list($dbConn); echo "<pre>"; print_r($customers); echo "</pre>"; } else { echo "Database not opened"; } MySQLDatabase Class: class MySQLDatabase { /** * MySql Connect to DB */ private $host; private $dbname; private $username; private $password; public $dbConn; function __construct($config){ $this->host = ($config['host']); $this->dbname = ($config['dbname']); $this->username = ($config['username']); $this->password = ($config['password']); } private function open_connection(){ try{ //$this->connection = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); $this->dbConn = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); echo "<script type=\"text/javascript\">window.alert(\"Connection Made\")</script>"; }catch(PDOException $e){ echo 'ERROR Inside the open_connection funtion: ' . $e->getMessage(); } } } /** * Create object */ $database = new MySQLDatabase($config); Functions File (will be moved to a Class next): function cust_list($dbConn){ //global $dbConn; try{ /** * Prepare */ $cust_list = $dbConn->prepare("select * from customer"); /** * Bind */ /** * Execute */ $cust_list->execute(); /** * Fetch from array */ $cust_list_array = $cust_list->fetchall(PDO::FETCH_ASSOC); /** * Return */ return $cust_list_array; } catch(PDOException $e){ echo"Inside cust_list " . $e->getMessage(); } } When sending in $dbConn I get: Notice: Undefined variable: dbConn in /Users/aaronjk/localhost/base_sites/php_base/public/index.php on line 34 Fatal error: Call to a member function prepare() on a non-object in /Users/aaronjk/localhost/base_sites/php_base/includes/functions.php on line 12 When setting $dbConn as global inside the function I get: Fatal error: Call to a member function prepare() on a non-object in /Users/aaronjk/localhost/base_sites/php_base/includes/functions.php on line 12 From What I've read I "Call to member function prepare() on a non-object in.. " is because I need the global connection $dbConn set in the called function, but I thought I was doing that.
  12. Sorry let me restate these from initial example... Yeah I guess I could have them all in......2 tables... One for the actual job listing, the the other have columns for each of the requirements for the job...... I guess I wanted to keep things separate and not have a row with 15 columns with only 1 entry and a number of rows per job... But might be better the other way... Is that more the common approach? These are things I'm finding out as I go, and here... thanx for the help and advice.. job: PK - job_id job_info1 job_info2 job_info3 job_resp: PK - job_resp_id Foreign Key job_id job_resp_info job_duties: PK - job_duties_id Foreign Key job_id job_duties_info
  13. The number of queries could very well be my the issue.. A brief example: Table1: PK - tb1_id col_info1 col_info2 col_info3 Table2: PK - tb2_id Foreign Key tb1_id col_info1 col_info2 col_info3 Table3: PK - tb3_id Foreign Key tb1_id col_info1 col_info2 col_info3 So what I'm doing is taking the PK tbl1_id and getting all the items from table2 and table3 that have that id..
  14. Yeah sure - that balance between not enough info and to much... And in all fairness this may not be an issue at all.. My question is how I'm returning my ending result set from the function. My first query returns an array, but before that will be sent back, I'm using a value from that returned array to get more information (more arrays) and adding that to the end... So my initial array, now contains array elements inside of it. I'm concerned I'm doing a little to much work because my ending return has arrays inside of arrays inside of arrays... hope that helps a bit... if not I'll try again..
  15. I have a set of tables for job listing. Right now I have a job table with id that is linked to multiple other tables that contain requirements for this job. For example: Job Responsiblities Job Duties Job Desired Skills Job Required Skills …..and so on. Lets say 10 different tables. The way my code is set up now I’m getting a couple levels of arrays returned. I’m wondering if there is a way to get rid of one of the levels. OR if this is how it should look. The returned data is displayed on a PHP Page. Some of the information returned is going to a table (Job Title, city, state, country). The rest - tables listed above will be put to a simple list in sections for each job. So an example of that will be: Job 1 Job Title Job Responsiblities list Job Duties list Job Desired Skills list Job Required Skills list Job 2 Job Title Job Responsiblities list Job Duties list Job Desired Skills list Job Required Skills list Here is what my return looks like using the <pre> </pre> tags Array ( [0] => Array ( [job_id] => 94 [jobOpening_ID] => 287 [customer] => customer [datePosted] => 2013-12-19 [dateRemoved] => 0000-00-00 [jobtitle] => jobTitle [city] => loc_city [state] => loc_State [country] => loc_Country [experience] => Experience [open] => 1 [summary] => Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary [0] => Array ( [0] => Array ( [resp] => Array ( [0] => Job ID 94 Responsibility 1 [1] => Job ID 94 Responsibility 2 [2] => Job ID 94 Responsibility 3 [3] => Job ID 94 Responsibility 4 [4] => Job ID 94 Responsibility 5 ) ) ) [1] => Array ( [0] => Array ( [duties] => Array ( [0] => Job ID 94 Duty 1 [1] => Job ID 94 Duty 2 [2] => Job ID 94 Duty 3 [3] => Job ID 94 Duty 4 [4] => Job ID 94 Duty 5 ) ) ) ) [1] => Array ( [job_id] => 92 [jobOpening_ID] => 305 [customer] => Cust - ABC [datePosted] => 2013-12-12 [dateRemoved] => 0000-00-00 [jobtitle] => ABC Job Title [city] => Location City [state] => Location State [country] => Location Country [experience] => ABC Experience [open] => 1 [summary] => Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello [0] => Array ( [0] => Array ( [resp] => Array ( [0] => Job ID 92 Resp 1 [1] => Job ID 92 Resp 2 [2] => Job ID 92 Resp 3 [3] => Job ID 92 Resp 4 [4] => Upgrade hardware/software knowledge and skills through tutorials, seminars, and education ) ) ) [1] => Array ( [0] => Array ( [duties] => Array ( [0] => Job ID 92 Duty 1 [1] => Job ID 92 Duty 2 [2] => Job ID 92 Duty 3 [3] => Job ID 92 Duty 4 [4] => Job ID 92 Duty 5 ) ) ) ) ) I'm wondering if I can / should remove the third [0].. [0][0][0][resp] [0][0][0][duties] Code: function jb_return(){ try{ global $db; //Prepare query - Limit 2 now for testing $jb_return_set = $db->prepare("SELECT * from job order by job_id desc LIMIT 2"); //execute $jb_return_set->execute(); //Get results from returned object $jb_return_array = $jb_return_set->fetchAll(PDO::FETCH_ASSOC); //Transfer the returned array - Not sure if I need this, but I wanted to keep the original $jb_return_array as is $jb_full_array_return = $jb_return_array; /* * Get Job Specific Details */ $count = 0; foreach($jb_return_array as $cur_id){ //echo '<script type="text/javascript">alert("Job ID Returned is: '. $cur_id['job_id'] .'")</script>'; //Get Job Responsibilities and add the array to the job array $jb_resp= array(); $jb_resp = get_jb_resp($cur_id['job_id']); array_push($jb_full_array_return[$count], array($jb_resp)); //Get Job Duties and add the array to the job array $jb_duty= array(); $jb_duty = get_jb_duties($cur_id['job_id']); array_push($jb_full_array_return[$count], array($jb_duty)); //Get Job Skills and add the array to the job array //Get Job Desired Skills and add the array to the job array // and so on with the other tables ++$count; } //Return result return $jb_full_array_return; } catch(PDOException $e){ echo 'ERROR: Inside jb_return Function' . $e->getMessage(); } } function get_jb_resp($jb_id){ //echo '<script type="text/javascript">alert("Inside the get_jb_resp - Job ID is: '.$jb_id.'")</script>'; try{ global $db; //Prepare query $jb_resp_set = $db->prepare("SELECT resp from job_resp where job_id = :jb_id and resp !=\"\""); //Bind the Value $jb_resp_set->bindValue(':jb_id', $jb_id, PDO::PARAM_STR); //execute $jb_resp_set->execute(); //Get results from returned object $jb_resp_array = $jb_resp_set->fetchAll(PDO::FETCH_ASSOC); foreach ($jb_resp_array as $row){ $return_jb_resp_array['resp'][] = $row['resp']; } //return $jb_resp_array; return $return_jb_resp_array; } catch(PDOException $e){ echo 'ERROR: Inside get_jb_resp Function' . $e->getMessage(); } } function get_jb_duties($jb_id){ try{ global $db; //Prepare query $get_jb_duty_set = $db->prepare("SELECT duties from job_resp where job_id = :jb_id and duties !=\"\""); //Bind the Value $get_jb_duty_set->bindValue(':jb_id', $jb_id, PDO::PARAM_STR); //execute $get_jb_duty_set->execute(); //Get results from returned object $get_jb_duty_array = $get_jb_duty_set->fetchAll(PDO::FETCH_ASSOC); foreach ($get_jb_duty_array as $row){ $return_jb_duty_array['duties'][] = $row['duties']; } //return $jb_resp_array; return $return_jb_duty_array; } catch(PDOException $e){ echo 'ERROR: Inside get_jb_duties Function' . $e->getMessage(); } } As of now the total job responses are under 15, with multiple (random) items in the other tables.. thanx all
  16. Thank you - I was hoping it was a version issue.. A bit frustrating spending some time tracking that down... But, seeing that I don't control that other server and it's easier for me to spend the time verses a week of e-mails, and conversations explaining why I think we should upgrade that box..
  17. ****NOTE**** I have a workaround for this, listed at the end. I'm self taught (OTJ) and am curious on why this works on one box and not another.. I have the below function, in a functions file, that works locally on my MAMP Server. But when I upload it to our Web Dev (Linux) server I can't get past loading the functions file, so nothing opens.. MAMP PHP: 5.4.10 Web Server: 5.3.3 The line that's getting me is this. Commenting it out things load fine for ALL pages. I just can't display this value.. //Get results from returned object $get_issue_info_value = $get_issue_info->fetch()['issue']; Full function: function get_issue_info($id){ //echo '<script type="text/javascript">alert("inside get_issue_info function - the ID: '.$id.'")</script>'; try{ global $db; //Prepare Query $get_issue_info = $db->prepare("select issue from website_issues where id = :id"); //Bind Values $get_issue_info->bindValue(':id', $id, PDO::PARAM_STR); //execute $get_issue_info->execute(); //Get results from returned object $get_issue_info_value = $get_issue_info->fetch()['issue']; /* * Debug: show returned value * echo '<script type="text/javascript">alert("Debug - Show value: '.$get_issue_info_value.'")</script>'; * */ //Return return $get_issue_info_value; } catch(PDOException $e) { echo 'ERROR inside the get_issue_info function: ' . $e->getMessage(); } } For testing I ran the below code in the functions file locally, using MAMP, I get: $get_issue_info_value = $get_issue_info->fetchAll(PDO::FETCH_ASSOC); Result: Array ( [0] => Array ( [issue] => A new issue Added ) ) $get_issue_info_value = $get_issue_info->fetch()['issue']; Result: A new issue Added FIX - this works locally and on the Web Dev server Fix in the functions file: //Get results from returned object //$get_issue_info_value = $get_issue_info->fetch(['issue']); $get_issue_info_value = $get_issue_info->fetchAll(PDO::FETCH_ASSOC); Fix in the php file: $issue_info = get_issue_info($id); /** Check the returned value*/ echo "<pre>"; print_r($issue_info); echo "</pre>"; $issue = $issue_info[0]['issue']; echo "<hr>"; /** Check the returned value*/ echo "Issue: " . $issue;
  18. I've been looking at this for a bit and can't seem to figure what's going on? I have used this code before and never had this issue.... I'm tryig to populate a dropdown menu from a MySql DB. The dropdown menu seems to skip the first array... I attached a screenshot that hopefully show's what I'm talking about.. any thoughts?
  19. grrrr - As i was editing my reply I saw a stupid error... thanx for pointing out the mysql_ line... first off I didn't catch that.. I am using mysqli (well converting all my mysql -> mysqli) and my insert statement was still using mysql_query and that syntax.. I changed to mysqli_query ($connection, $query) and it works... thanx for the extra pair of eyes and the quick response...... Who knows how long I would have looked (overlooked) that..
  20. grrrr - As i was editing my reply I saw a stupid error... thanx for pointing out the mysql_ line... first off I didn't catch that.. I am using mysqli (well converting all my mysql -> mysqli) and my insert statement was still using mysql_query and that syntax.. I changed to mysqli_query ($connection, $query) and it works... thanx for the extra pair of eyes and the quick response...... Who knows how long I would have looked (overlooked) that..
  21. Insert function not working like the select functions are.. :~ I have a functions file that contains a number of mysqli_query query's that other php pages successfully call, including the page in question. For round numbers I have 10 functions total. Of the 10, 9 are select query's, 1 is an insert. All of the select query's work including 2 on the page in question. These 2 query's populate 2 drop down menus in a form. When I submit the form I am $_POST ing all the fields to another PHP file that parses the data, calls the insert function -> sends the values, then sends an e-mail using PHPMailer.. When I call the Insert query (submit the form), I am returned "Error updating databaseNo database selected" Error. All of the php pages have an include statement on top pointing to a connection file. IF I put a DB connection string inside the insert function, per below, the insert function works when called.. There's gotta be something basic I'm missing with how I have my stuff setup.. Does anybody have advice? Or I guess I could have everything on one page / file.... mysql_connect("server", "user", "pass") or die('Can\'t connect because:' .mysql_error()); mysql_select_db ("database"); thanx
  22. Moving site from a CentOS PHP 5.3.3 and apache (someone else set up for me) to a Windows 2008R2 running IIS (Replacing a site here). I PHP 5.4.18. A couple things I can’t get working / or figured out and am wondering if they are connected Scan this dir for additional .ini files On my CentOS: phpinfo.php reads: /etc/php.d Contains about 30 files Can’t find this config in the php.ini file. From what I’ve read this is set when PHP is compiled... On my Windows server it reads (none) - How can I config this on my windows box Mail: I have a Send us a message php page that on my CentOS server works, on my Windows it doesn’t. No error, the form is cleared (redirect back to the blank page) like everything is working, but nothing is received. The Send us a message page posts the user input values to another php page that packages up the info and sends an e-mail out.
×
×
  • 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.