Jump to content

lewashby

Members
  • Posts

    37
  • Joined

  • Last visited

lewashby's Achievements

Member

Member (2/5)

0

Reputation

  1. While following along the lessons I forgot I had moved all the files in the previous working lesson into a sub directory 'old' including the jquery file. I feel stupid, and it won't be the last time. Thanks for your help Jacques1. It is solved.
  2. I see the 404 error and I also see that is says '$' is not defined. I'm following along with a web dev course on udemy.com and my pages look identical to his so I don't understand what the problem is. I thought $(document).ready() was valid syntax for a .js file?
  3. My browser is loading the webpage just fine and there are no errors reported in /var/log/apache/error.log but I can't get this simple jQuery alert to show up after refreshing the browser. Do you see anything wrong with me code? Thanks. HTML <-index.html <!DOCTYPE html> <html> <head> <title>jQuery Content Slider</title> <link rel='stylesheet' href='css/style.css'> <script src='jquery-3.0.0.min.js'></script> <script src='js/script.js'></script> </head> jQuery <- js/script.js $(document).ready(function() { alert('Doc is ready'); });
  4. In the following pages I'm trying to validate if a user is signed in or not. If the user is signed in I would like to see 'Log Out' printed to the screen(I'll do more with that later). If the user is not signed in I would like to see a login form at the top right of the screen. As it stands I'm only seeing 'Log Out' on the screen, I can't get the form to show up anymore. I thought it might be because the session variable was still hanging around but I restarted my computer to make absolutely sure but I'm still just getting 'Log Out'. At the moment I need this program to work as is as much as possible. If you see an entirely different approach that you would use that's fine but I don't currently have the time to go changing a lot, I need to get this going kinda quick. Thanks. records-board.php <?php require_once('includes/init.php'); if(!isset($_SESSION)) { init_session(); } ?> <html> <head> <Title>Pop Report</title> <link rel="stylesheet" type="text/css" href="styles/popreport2.css"> <h1>Pop Report</h1> </head> <body> <?php if(isset($_POST['nameinput']) && isset($_POST['passinput'])) { $nameinput = $_POST['nameinput']; $passinput = $_POST['passinput']; User::sign_in($nameinput, $passinput); } if(!isset($_SESSION['user'])) { print_form(); } else { echo "Log Out "; echo $_SESSION['user']->name; // this line was just trouble shooting, it told me nothing! } ?> user.php <?php if(!isset($_SESSION)) { init_session(); } class User { public $name; public function __construct($username, $password) { $connection = get_db_connection(); $query = $connection->query("SELECT * FROM users WHERE username='$username' AND password='$password'"); if(!$query) { echo "Invalid username or password"; } else { $result = $query->fetch(PDO::FETCH_ASSOC); if(!$result['username'] == $username || !$result['password'] == $password) { echo "Invalid username or password"; } else { $this->name = $result['username']; } } } public static function sign_in($username, $password) { $_SESSION['user'] = new User($username, $password); } } ?> <?php function print_form() { echo "<form id='loginform' name='loginform' action='records-board.php' method='post'>"; echo "Username: <input type='text' name='nameinput'>"; echo "Password: <input type='text' name='passinput'><br />"; echo "<input type='submit' value='Sign In'>"; echo "</form>"; } ?>
  5. If I have a php file that generates an html form from another php file which file would be the default file that would try to execute if I leave the action field blank in the html form? The php file that the form sits in or the php file that it's called from? Thanks.
  6. <?php require_once('init.php'); function print_rows($inmates) { foreach($inmates as $inmate) { echo "<tr>"; echo "<td><span class='rightpadding'>$inmate->get_property('first_name');</span>$inmate->get_property('number');<span class='rightpadding'>(W)</span>Facility<br /><br /><span class='dates'>8-05-15 <span class='red'>/</span> 8-08-15</span><a href=''><span class='edit'>Edit</span></a></td>"; echo "</tr>"; } } ?> In the code above my inmate object method calls are being displayed a literal strings in the output. How can I get these to expand in this string? I also tried concatenation with the . operator but the page wouldn't load at all using that method.
  7. When I load this into the browser I get a bunch of zeros '0' stacked on top of each other on the left side of the screen instead of getting the name and numbers of the individuals. I added this line in one of the files to try and find the problem but as it turns out this line is outputting exactly what I wanted and expected it to output so I don't know why the rest of the program isn't working. print_r('The $attribute variable = ' . $attribute . '<br />'); <- that's the line I added into the file inmate.php and it shows that the variable $attribute has exactly what it needs to have but when I try and output this information from the test.php file I get the zeros. test.php <?php require_once("./database.php"); require_once("./inmate.php"); $inmates = Inmate::get_inmates(); foreach($inmates as $inmate) { print $inmate->inmate_property['first_name'] . " " . $inmate->inmate_property['last_name'] . " " . $inmate->inmate_property['number'] . "<br />"; } ?> inmate.php <?php require_once("./database.php"); class Inmate { // public $first_name; // public $last_name; // public $full_name; // public $race; // public $number; // public $facility; // public $type_of_transit; public $inmate_property = array('first_name' => '', 'last_name' => '', 'full_name' => '', 'race' => '', 'number' => 0, 'facility' => '', 'type_of_transit' => ''); public function __construct($result) { // $this->first_name = $result['first_name']; // $this->last_name = $result['last_name']; // $this->number = $result['number']; foreach($result as $attribute) { print_r('The $attribute variable = ' . $attribute . '<br />'); $this->inmate_property[$attribute] = $attribute; } } public function get_property($property) { return $this->$property; } public function set_property($property, $value) { $this->$property = $value; } public static function get_inmates() { $connection = get_db_connection(); $inmates = array(); $sql = "SELECT * FROM inmate_board"; $query = $connection->query($sql); while($result = $query->fetch(PDO::FETCH_ASSOC)) { array_push($inmates, new Inmate($result)); } return $inmates; } } ?> I'm trying to setup xdebug for vim so I don't have to post this many questions but I'm having some trouble getting that going.
  8. I'm getting this error -> PHP Warning: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/popreport/includes/database.php on line 10 form /var/log/apache/error.log Here's my database.php file <?php require_once("./constants.php"); function get_db_connection() { try { $db_connection = new PDO("mysql:host=HOST;dbname=DB_NAME", DB_USER, PASSWORD); $db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // $query = $db_connection->query("SELECT * FROM inmate_board"); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br />"; die(); } return $db_connection; } ?> and here's my constants.php file <?php define('HOST', 'localhost'); define('DB_NAME', 'xxxx'); define('DB_USER', 'xxxx'); define('PASSWORD', 'xxxx); ?> Any ideas? Thanks for any and all replies.
  9. I'm getting the following errors when I run `cat /var/log/apache/error.log` -> PHP Notice: Undefined variable: db_connection in /var/www/html/popreport/includes/inmate.php on line 18 -> PHP Fatal error: Call to a member function query() on a non-object in /var/www/html/popreport/includes/inmate.php on line 18 When I try this in my browser I start with test.php test.php <?php require_once("./database.php"); require_once("./inmate.php"); // foreach($query as $row) // { // print_r($row) . "<br />"; // } $inmate = array(); $inmate = new Inmate($inmate); foreach($inmate as $row) { print $row->firstl_name . "<br />"; } ?> database.php <?php include("./constants.php"); try { $db_connection = new PDO("mysql:host=$host;dbname=$db_name", $db_user, $password); $db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br />"; die(); } ?> inmate.php <?php require_once("./database.php"); class Inmate { private $first_name = ''; private $last_name = ''; private $full_name = ''; private $race = ''; private $number = 0; private $facility = ''; private $type_of_transit = ''; public function __construct($inmate) { $sql = "SELECT * FROM inmate_board"; $query = $db_connection->query($sql); $result = $query->fetch(PDO::FETCH_ASSOC); foreach($result as $row) { $this->$first_name = $result['first_name']; } } public function get_property($property) { return $this->$property; } } ?> In inmate.php I also tried to change the line `$query = $db_connection->query($sql);` to `$query = global $db_connection->query($sql);` but I didn't have any luck here either. Any ideas?
  10. I don't see a 'Mark Solved' button?
  11. Reconstructed the whole thing, now it works and it's a lot more simple. Thanks.
  12. test.php <?php include('./database.php'); $connection = new Connection(); ?> database.php <?php include('./constants.php'); class Connection { function __construct() { try { $db_connection = new PDO("mysql:host=$host; dbname=$db_name", $db_user, $password); if($db_connection) { $db_connections = self::return_connection(); } } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br />"; die(); } } static function return_connection() { return $db_connection; } } ?> In the above program I keep getting the error -> Error!: SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO) in my web browser but I'm not getting that error at all in /var/log/apache/error.log, just a few undefined variable errors. I can also log into MySQL/MariaDB's root account just fine with a password, but if I try to log in without that password I get the exact error above on my command line. garrett@mint-desktop /var/www/html/popreport/includes $ mysql -u rootERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) garrett@mint-desktop /var/www/html/popreport/includes $ mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 47 Server version: 5.5.46-MariaDB-1ubuntu0.14.04.2 (Ubuntu) Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> Okay, after looking at those undefined variables in database.php I believe that the file constants.php isn't being included despite the call to include() on line 4 of database.php, any ideas? Thanks. I'm trying to get the file database to php to return a PDO connection object for other parts of the site so any advice in addition would be much appreciated, thanks again.
  13. [Linux] PHP Notice: Undefined variable: connection in /var/www/html/popreport/functions.php on line 23 PHP Fatal error: Call to a member function query() on a non-object in /var/www/html/popreport/functions.php on line 23 The fuction output in the following program is called from another file called records records-board.php If you look at the program below you'll see that I did define $connection above line 23 in the file functions.php And for the second error I'm really not getting it because that same foreach loop was working fine with the exact same argument list when it was in the file records-board.php, but now that I've copied most of the code from records-board.php and placed it in functions.php all the sudden my program can't see the variable $connection and has a problem with my foreach loop on line 23. Again, both of those lines worked fine when they were in another file. functions.php <?php //session_start(); // open a DB connectiong $dbn = 'mysql:dbname=popcount;host=127.0.0.1'; $user = 'user'; $password = 'password'; try { $connection = new PDO($dbn, $user, $password); } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } $sql = "SELECT full_name, tdoc_number, race, facility FROM inmate_board WHERE type = 'COURT'"; function output() { foreach($connection->query($sql) as $row) { echo "<tr><td>$row[full_name]</td></tr>"; } } ?> records-board.php <? include 'functions.php'; php output(); ?> Any ideas?
  14. I am having trouble with one of my php programs because document_root is pointing to /var/www/ rather than the sub direcotry that the site is actually in, /var/www/project/site/ How can set $_SERVER['document_root'] = the directory of my site rather than /var/www/ which is just root folder of all my web projects, not the projects themselves.
×
×
  • 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.