Jump to content

lewashby

Members
  • Posts

    37
  • Joined

  • Last visited

Everything posted by lewashby

  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.
  15. I think I got it with the following. I don't think the isset function is doing very much. if(isset($_POST['newpassword1']) && $_POST['newpassword1'] != '' && isset($_POST['newpassword2']) && $_POST['newpassword2'] != '')
  16. That's not the if I'm having trouble with, it's the fact that the next one is not being ran at all. The next IF "if(isset($_POST['newpassword1']) && isset($_POST['newpassword2']))", is an IF statement unto itself so I don't see why it isn't running by default after the above if/else statements gets through. After the user enters the new password twice in the form following the if/else should run by default, which in this case is my isset IF, but all I'm getting is "Invalid Password" from the preceding if/else. Oh, and how the passwords are not encrypted.
  17. Yes, I understand how an if/else system works. I was referring to a form that may have already been printed to the browser. I've adjusted the code but I keep getting "Invalid password" no matter what I enter into the form just above it. Take note that the IF the creates this form is based upon outside variables, the invalid message should only run if the variables the feed the IF statement that creates the form are incorrect, invalid should not be displayed as a result of anything that's entered into the form you see here, or at least that what I intended. So my if(isset) functions never runs. <?php session_start(); $hash = $_SESSION['hash']; $email = $_SESSION['email']; $passwd = $_POST['passwd']; $db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE); if(!$db) { echo "Could not open/access DB"; } else { $result = $db->query("SELECT password, rstring FROM users WHERE email='$email'"); $row = $result->fetchArray(); if($row['password'] == $passwd) { echo "<form>"; echo "<table>"; echo "<tr><td>"; echo "New Password<input type='text' name='newpassword1'</td></tr>"; echo "<tr><td>"; echo "Re-Enter Password<input type='text' name='newpassword2'</td></tr>"; echo "<tr><td><input type='submit' value='submit'></td></tr>"; echo "</table>"; echo "</form>"; } else { echo "Invalid password<br />"; } if(isset($_POST['newpassword1']) && isset($_POST['newpassword2'])) { echo "This is from the form $_POST[newpassword1]<br />"; echo "This is from the form $_POST[newpassword2]<br />"; } } ?>
  18. Thanks. So what if I want my current form to vanish while being replaced my the new form rather than just stacking the forms one on top of the other? Thanks again.
  19. In the program below I would like to process the variables from the the php generated form by using this same file with code I haven't written yet. The problem is if I add this very script to the action attribute of the form, the page will start at the top again and keep asking the user to enter a password. I would like to continues processing the form variables just further down the page/file of this document, how can I, or can I accomplish this? Thanks. <?php session_start(); $hash = $_SESSION['hash']; $email = $_SESSION['email']; $passwd = $_POST['passwd']; $db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE); if(!$db) { echo "Could not open/access DB"; } else { $result = $db->query("SELECT oldpasswd, hash FROM users WHERE email='$email'"); $row = $result->fetchArray(); if($row['oldpasswd'] == $passwd) { echo "<form>"; echo "<table>"; echo "<tr><td>"; echo "New Password<input type='text' name='newpasswd1'</td></tr>"; echo "<tr><td>"; echo "Re-Enter Password<input type='text' name='newpasswd2'</td></tr>"; echo "</table>"; echo "</form>"; } else { echo "Invalid password<br />"; } } ?>
  20. I quit being lazy and figured it out. Thanks all.
  21. Is it possible for a php file the contains a static html form to call itself? What I'm wanting to do is have the form point to the php file that the form itself is in, I'll just have part of the file as static html and the other part of the file will be the php script that will operate on the data supplied by the form.
  22. In the following program I'm getting the error listed as my title when I run the page. Any ideas? It says the problem is on line 6 <?php session_start(); include "resources.php" $email = $_SESSION['email'] = $_POST['email']; $psswd = $_SESSION['psswd'] = $_POST['psswd']; if(querymatch($email, $psswd)) { header("location: ./changepassword.html"); break; } echo "Unknown username and or password"; ?>
  23. In the following program the strpos() functions work for most cases are failing in one instance. If you type nothing, something completely random, or the email address and or password with any extra characters the program will not let the user through as they are unknown. The problem is that if you type a partial email address or password that's in the text file it's still substring of that line and is thus cleared as a known user. How can I better protect the process so that strpos() is checking $line for exact matches of email, & password? They are both on the same line separated with only white spaces. <?php session_start(); $_SESSION['email'] = $_POST['email']; $_SESSION['psswd'] = $_POST['psswd']; $db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE); $file = fopen("./accounts.txt", 'r+') or die("Failed to open file"); while(!feof($file)) { $line = fgets($file); if(strpos($line, $_SESSION['email']) !== false) { if(strpos($line, $_SESSION['psswd']) !== false) { header("location: ./changepassword.html"); break; } } } echo "Unknown username and or password"; fclose($file); ?>
×
×
  • 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.