lewashby 56 Junior Poster

I've tinkered with php in the past but I'v also enjoyed playing around with python. I have been wanting to give python a try as a possible alternative to php but I haven't had much luck. All of the videos I find on the subject are about setting up Django or Flask. I find trying to set up a project in either one of these more troublesome than setting up a LAMP stack which I use for ALL of my php projects. Is there no way to use Python along beside Apache the way I do with PHP without having to go through all the trouble of Django or Flask?

lewashby 56 Junior Poster
 python3 pythonscript.py 
Traceback (most recent call last):
  File "pythonscript.py", line 1, in <module>
    import pysftp as sftp
  File "/usr/local/lib/python3.4/dist-packages/pysftp/__init__.py", line 12, in <module>
    import paramiko
  File "/usr/local/lib/python3.4/dist-packages/paramiko/__init__.py", line 30, in <module>
    from paramiko.transport import SecurityOptions, Transport
  File "/usr/local/lib/python3.4/dist-packages/paramiko/transport.py", line 32, in <module>
    from cryptography.hazmat.backends import default_backend
ImportError: No module named 'cryptography'

Why am I getting the above error when I run the following script. Please note that I've tried using just python (which is 2.x) and python3 and I've installed paramiko, pycrypto, and pysftp for by 2.x and 3

import pysftp as sftp

def push_file_to_server():
    s = sftp.Connection(host='address', username='user', password='xxx')
    local_path = 'testme.txt'
    remote_path = '/home/testme.txt'

    s.put(local_path, remote_path)
    s.close()

push_file_to_server

Thanks.

lewashby 56 Junior Poster

Thanks. backuppc was actually recommended to me by another very experienced Linux administrator after I told him I was planning on using rsync. It's at his house that I'll be keeping the pi2 + hdd. So why would backuppc be a bad choice? When I told the other guy I was planning on using rsync he said that I didn't need to use rsync because rsync was going to make a copy of my files and that I didn't need to make copies but that incremental backups would be better so he recommended I use backuppc, he then told be that backuppc uses rsync which did confuse me a little, why not just stick with my original plan and use rysnc then?

lewashby 56 Junior Poster

I'm trying to get my Mint desktop computer's home directory and my Debian media server's movies/shows directoiries backed up. When this is all said and done I'll be backing everything up to a 5 TB external USB HDD with it's own powers source connected to a Raspberry Pi 2 stored away from my house via colocation. But I'd like to get the many TBs of data I have copied before I move the PI2 + HDD off site. I've been reading here -> http://backuppc.sourceforge.net/BackupPC-4.0.0alpha3_doc.html#BackupPC-Introduction on setting up backuppc but my head is starting to hurt. When I read over that material it sounds like they are expecting the destination of my data to be the server that's running backuppc but that's not how I'd like to run this. I want my backups to be initiated from my in house desktop and media server (the sources) using backuppc, to the RP2+HDD (destination). Is this possible?
Also, before I move the RP2 off site what would be the best means of using backuppc to copy my data locally? Can I setup backuppc to copy from my desktop and server to the HDD via the USB connection and then change the backuppc configuration after moving the PI2 off site or am I doing to need to do this over my home network via the RP2's ethernet port? If anyone has any suggestions and or corrections please give me a hand, I've never used backuppc and I have no idea what …

lewashby 56 Junior Poster

I'm going to look into this cubieboard thing, that sounds ineteresting. I've got the PI 2 and a 5 TB external HD with it's own power source. What I want to do now is to use backuppc to backup my Debian media server and my Mint desktop to the USB external HD. After the backup is completed localy I can then move the PI 2 to it's remote location and start regular scheduled backups. But at this point I am stuck because I don't know how to use backuppc, I have it intalled but I don't know how to launch it in the browser. Once I have backedup everthing localy and move the PI 2 to it's remote location I want to the backups to be initiated from my Mint desktop and my Debian media server, so what I'm wanting is for the machines in my house to be the server and the source and the PI 2 and it's acompianying 5 TB extern HDD to be the destination. Is this a possible setup and can anyone help me with this?

Also, I was just looking the the backuppc directory /etc/backuppc and I seem to have found an infinate regretion of directories. Could someone please explain.

garrett@mint-desktop /etc/backuppc/pc $ ls
apache.conf  config.pl  hosts  htpasswd  localhost.pl  pc
garrett@mint-desktop /etc/backuppc/pc $ cd pc/
garrett@mint-desktop /etc/backuppc/pc/pc $ ls
apache.conf  config.pl  hosts  htpasswd  localhost.pl  pc
garrett@mint-desktop /etc/backuppc/pc/pc $ cd pc/
garrett@mint-desktop /etc/backuppc/pc/pc/pc $ ls
apache.conf  config.pl  hosts  htpasswd  localhost.pl  pc
garrett@mint-desktop /etc/backuppc/pc/pc/pc $ cd …
lewashby 56 Junior Poster

I haven't used it yet but as of right now I'm still planning on using backuppc. I have many TBs to backup most of that up locally before deploying the server outside my home network. Then I'll only be backing up the difference when I run my backups.

lewashby 56 Junior Poster

I have been trying to learn to program for years. I've played around with C, C++, Python, & PHP but I would not dare call myself a programmer. I want to setup a remote server with lots for storate, I figured that Raspberry Pi 2 + hard drives would be a cheap way of achieving this goal, and I've heard good things about backuppc from Linux users.

lewashby 56 Junior Poster

I've been wanting to build a backup server for my Mint desktop as well as for my Debian media server for a while now. To save money I purchased a Raspberry Pi 2 and I'm going to store it at a friends house who owns an ISP and thus has plenty of bandwidth, and I've lived through one house fire already so I don't feel safe about backing everything up here. As for backing up my home directory I could purchase an SSD or a traditional HD, but for all the media stored on my Debian media server I simply can not afford an SSD due to the massive storage capacity needed. I'd like some suggestions on HDs for my media and my Mint home directory should I decide to go with a HD. Here are some things that are on my mind. I'm a little leery of external HDs because I've seen them fail a lot but I don't see much of a way around it because the Raspberry Pi 2 will simply not have the ability to power an internal HD. So given that I will probably have to go with an external drive, should I use one that doesn't require a separate power source with USB being it's only connection or should I go with one that has an independent power source? I'm also concerned about power down issues. I would feel better if the drive would power down when it's not being used and thus would …

lewashby 56 Junior Poster

Update, I reformatted the USB stick and instead of buring the Mint image on it I burned the Ubuntu image on it and now it's working fine. Go figure. Thanks.

lewashby 56 Junior Poster

I'm googling UEFI right now. If it was a UEFI issue would that be a problem with the USB stick or the laptop? I did notice that when I tried to format my USB sticks in Gparted this is what I get when it first fires up.

/dev/sdf contains GPT signatures, indicating that it has a GPT table. However, it does not have a valid fake msdos partition table, as it should. Perhaps it was corrupted -- possibly by a program that doesn't understand GPT partition tables. Or perhaps you deleted the GPT table, and are now using an msdos partition table. Is this a GPT partition table?

Does that tell us anything?

lewashby 56 Junior Poster

update

It was an issue with power button/motherboard ribbon cable. I have now fixed that issue but I'm still having problems. The laptop has a new 250 GB Samsung SSD in it and I wrote the ISO for Linux Mint 17 Cinnamon to a USB and fired the laptop up with that in the USB port in hopes of installing the Mint OS onto the new SSD. When the laptop turns on GRUB comes up with the option of starting in Mint but after pressing Enter the screen goes black and nothing happens. Any ideas here? Thanks again everyone.

lewashby 56 Junior Poster

I'll give that a try rproffitt. No rubberman, it's like that power button isn't even connected to anything, absolutly nothing happens when you press the button.

lewashby 56 Junior Poster

My brothers laptop recently died, I believe due to a failed hard drive because when you turned it on you couldn't get out of the BIOS. I unscrewed the laptop's bottom from it's keyboard and replaced the hard drive but now it won't even turn on at all, I can't even get a BIOS screen. The only thing that I could visibly see that went wrong when I opened it was two ribbon cables came undone. One was very skinny and the other was wider and they went from the mother board to right under the laptop finger pad. I believe I plugged both of them back in correctly but I'm dead in the water. Any ideas or suggestions?

lewashby 56 Junior Poster

Thanks. So is student a dictionary in each iteration of this code?

lewashby 56 Junior Poster
import pymongo

uri = "mongodb://127.0.0.1:27017"
client = pymongo.MongoClient(uri)
database = client['fullstack']
collection = database['students']

students = [student['mark'] for student in collection.find({}) if student['mark'] == 99.0]
print(students)

In the program above how does this work? Why is the if statement after the execution code? I would expect the if to be before the for. And if student['mark'] contains a value other than the string mark then it looks to me like student behaving like a dictionary with a key/value pair and not a python list. It probobly doesn't help that I've been playing in php and looks exactly like a php associative array.

lewashby 56 Junior Poster

Okay so I fixed that and now I'm getting this.
Sun Jan 10 14:57:42.529 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Sun Jan 10 14:57:42.529 [websvr] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:28017
Sun Jan 10 14:57:42.529 [initandlisten] ERROR: addr already in use

So now I'm having to start MongoDB with using mongod --port 28018 instead of the default 28017. How can I figure out what's using the port that MongoDB is also wanting to use? Thanks.

lewashby 56 Junior Poster

When I tried to start MongoDB with the mongod command I got the following.

garrett@mint-desktop ~ $ mongod
mongod --help for help and startup options
Sun Jan 10 14:50:55.049 [initandlisten] MongoDB starting : pid=23327 port=27017 dbpath=/data/db/ 64-bit host=mint-desktop
Sun Jan 10 14:50:55.050 [initandlisten] db version v2.4.9
Sun Jan 10 14:50:55.050 [initandlisten] git version: nogitversion
Sun Jan 10 14:50:55.050 [initandlisten] build info: Linux orlo 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 17:37:58 UTC 2013 x86_64 BOOST_LIB_VERSION=1_54
Sun Jan 10 14:50:55.050 [initandlisten] allocator: tcmalloc
Sun Jan 10 14:50:55.050 [initandlisten] options: {}
Sun Jan 10 14:50:55.050 [initandlisten] exception in initAndListen: 10296 
*********************************************************************
 ERROR: dbpath (/data/db/) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
Sun Jan 10 14:50:55.050 dbexit: 
Sun Jan 10 14:50:55.050 [initandlisten] shutdown: going to close listening sockets...
Sun Jan 10 14:50:55.050 [initandlisten] shutdown: going to flush diaglog...
Sun Jan 10 14:50:55.050 [initandlisten] shutdown: going to close sockets...
Sun Jan 10 14:50:55.050 [initandlisten] shutdown: waiting for fs preallocator...
Sun Jan 10 14:50:55.050 [initandlisten] shutdown: lock for final commit...
Sun Jan 10 14:50:55.050 [initandlisten] shutdown: final commit...
Sun Jan 10 14:50:55.050 [initandlisten] shutdown: closing all files...
Sun Jan 10 14:50:55.050 [initandlisten] closeAllFiles() finished
Sun Jan 10 14:50:55.050 dbexit: really exiting now

I then ran sudo mkdir /data/db and now I'm getting this.

garrett@mint-desktop ~ $ mongod
mongod --help for help and startup options
Sun Jan 10 14:52:24.797 [initandlisten] MongoDB starting : pid=23762 port=27017 dbpath=/data/db/ 64-bit host=mint-desktop
Sun Jan 10 14:52:24.797 [initandlisten] db …
lewashby 56 Junior Poster

I changed my css from this
.facility { position: relative; float: top; float: right; }
to this
.facility { text-align: right; vertical-align: top; color: red; }
And the text that was on the right side of my cell which was were I wanted it snapped all the way to the left until it ran into the next item in the cell. It appears that the float: right; and text-align: right; is not. What am I missing here?
The red is only there so I can see if the html and css are connecting at all. Also, when I took away the span tag and only left a class name in the <> it failed to even change the color.

echo "<tr>";
        echo "<td><class='name'>{$inmate->get_property('full_name')} ({$inmate->get_property('race')})</class><span class ='number'>{$inmate->get_property('number')}</span><span class='facility'>{$inmate->get_property('facility')}</span><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>";
lewashby 56 Junior Poster

I'm trying to align 3-5 items up in a table cell, three are on the top and two are on the bottom. In each of my table cells I want the first item to be at the top left of cell and the third item I want to be at the top right of the cell. Those two are working just fine with a CSS class .classname { position: relative; float: top; float: left; } and likewise for the right floating item. It's the 2nd item in the cell I'm having trouble with, I can't get it to float in the top center of the cell. .classname { position: relative; float top; float: center; } Any ideas how I can pull this off? All the items are currently in <span> tags.
Thanks for any and all replies.

lewashby 56 Junior Poster

I wasn't getting an error or anything it's jut that I noticed that my POST variables appeared in the URL, .com?var=x&var=y
What do you mean that my HTML MUST have a <head> tag? I'v never had an issue from leaving it off. I don't always need one, espesially when it's just a small page meant mainly for a little PHP output.

cereal commented: correct +14
lewashby 56 Junior Poster

Thanks, I'll give that a try.

Here's my code.

<?php

require_once('init.php');

$inmates = Inmate::get_inmates('COURT');

foreach($inmates as $inmate)
{
    print $inmate->get_property('first_name') . " "  . $inmate->get_property('last_name') . " " . $inmate->get_property('number')  . "<br />";
}

?>

<html>
    <body>
    <br />
    <br />
        <form method='post'>
            Username: <input type='text' name='username'><br /><br />
            Password: <input type='text' name='password'>
            <input type='submit' value='submit'>
        </form>
    </body>
</html>

<?php

echo $_POST['username'] . '<br />';
echo $_POST['password'] . '<br />';

?>
lewashby 56 Junior Poster

http://www.w3schools.com/php/php_forms.asp

On the page above I read that GET variables are send via the url and POST variables are sent as an HTTP request. When I tried POST with a simple php script all of my POST variables were still in the URL which is what I was expecting for GET. Could someone clear this up for me? Thanks.

lewashby 56 Junior Poster

Thanks.

lewashby 56 Junior Poster

I'm reading 'C++ For Dummies 7th Edu' and I'v ran into this little snipet that's confusing me.

BOOK
You can add const-ness, however, as in the following

void fn(char* pName)
{
    // declare following is allowed even though
    // declared Student(const char*)
    Student s(pName);
    // ...do whatever...
}

The function fn() passes a char* string to a constructor that promises to treat the string as if it were a constant.
/BOOK
The example before this used a constructor that was almost identical Student(const* pName). The only difference I see is that the Student constructor in the fn() function doesn't have a variable name given to hold it's argument, I didn't think that was legal. I don't see what the book is driving at, all this short snippet did was to place the Student object creation in a regular function and leave out the variable name of the paramater in the student constructor? What am I missing here? Thanks.

lewashby 56 Junior Poster

Update, as of today I'm not getting these errors under the /var/log/apacher/error.log file, note that I wasn't even trying to edit the project under the udemy directory, that must have been loaded because google chrome loads every tab when it starts up. It says no such file or directory for the xdebug.so file but I verified that the files are there with the find command, that's where I got the path so I could put it in the php.ini file.

garrett@mint-desktop ~ $ cat /var/log/apache2/error.log
[Sat Dec 26 12:24:26.923482 2015] [mpm_prefork:notice] [pid 6988] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.14 configured -- resuming normal operations
[Sat Dec 26 12:24:26.923532 2015] [core:notice] [pid 6988] AH00094: Command line: '/usr/sbin/apache2'
[Sat Dec 26 21:30:03.324359 2015] [:error] [pid 6994] [client 127.0.0.1:59142] PHP Fatal error: Call to undefined function redicrect() in /var/www/html/udemy/php-oop/gallery/admin/includes/header.php on line 5
[Sat Dec 26 21:30:03.325177 2015] [:error] [pid 6994] [client 127.0.0.1:59142] PHP Stack trace:
[Sat Dec 26 21:30:03.325203 2015] [:error] [pid 6994] [client 127.0.0.1:59142] PHP 1. {main}() /var/www/html/udemy/php-oop/gallery/admin/index.php:0
[Sat Dec 26 21:30:03.325210 2015] [:error] [pid 6994] [client 127.0.0.1:59142] PHP 2. include() /var/www/html/udemy/php-oop/gallery/admin/index.php:1
[Sat Dec 26 22:06:06.614227 2015] [:error] [pid 6991] [client 127.0.0.1:60717] PHP Fatal error: Call to undefined function redicrect() in /var/www/html/udemy/php-oop/gallery/admin/includes/header.php on line 5
[Sat Dec 26 22:06:06.614259 2015] [:error] [pid 6991] [client 127.0.0.1:60717] PHP Stack trace:
[Sat Dec 26 22:06:06.614270 2015] [:error] [pid 6991] [client 127.0.0.1:60717] PHP 1. {main}() /var/www/html/udemy/php-oop/gallery/admin/index.php:0
[Sat Dec 26 22:06:06.614277 2015] [:error] [pid 6991] [client 127.0.0.1:60717] PHP 2. include() /var/www/html/udemy/php-oop/gallery/admin/index.php:1
[Sat Dec 26 23:28:51.517560 2015] [mpm_prefork:notice] [pid 1762] …
lewashby 56 Junior Poster

I followed this site -> https://www.box.com/blog/how-to-debug-php-with-vim-and-xdebug-on-linux/
but I'm not having much luck. I followed the firections and my phpinfo() functions is showing that xdebug is up and running but I see don evidence of xdebug from within vim. I typed in my localhost url, localhost/mysite.php?XDEBUG_SESSION_START=1 and then wen to vim and pressed f5 but that didn't seem to have an effect at all. When I run cat /var/log/apache/error.log I get no errors showing.
And here are my xdebug setting in my /etc/php5/apache/php.ini file

;My Modules
[bash][Zend] zend_extension = /usr/lib/php5/20121212/xdebug.so xdebug.remote_enable = 1
xdebug.remote_port = 9000 xdebug.remote_host = localhost [/bash]

Any ideas? Thanks.

lewashby 56 Junior Poster

Thanks, that got it.

lewashby 56 Junior Poster
<?php

include('./constants.php');

try
{
    $connection = new PDO("mysql:host=$host; dbname=$db_name, $db_user, $password");
}

catch (PDOException $e)
{
    print "Error!: " . $e->getMessage() . "<br />";
    die();
}

?>
lewashby 56 Junior Poster

I get the following in my web browser when I try to connect to my mariaDB database.
Error!: SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)
It also doesn't matter if I use mariaDB root or a regular users credentials, I get the same thing.
The error above that's showing up in my web browser is the same error I get if I leave the -p option off when logging into mysql through the command line.
mysql -u root -> Error!: SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)
mysql -u root -p all good

Any ideas? Thanks.

lewashby 56 Junior Poster

I hot the following program from the book 'C++ For Dummies' but have two questions about it. First I compiled the program but I'm afraid to run because the memery created from the heap does not appear to me to get de-allocated. Am I correct in not wanting to run this and is my reason valid? Secondly, on the line Student* pS = new Student; is it alway a rule that memory created from the heap must be access via a pointer? I know when I removed the * I get the following error from g++. constructor.cpp:30:22: error: conversion from ‘Student*’ to non-scalar type ‘Student’ requested -> Student pS = new Student;

// constructor - example that invokes a constructor
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

class Student
{
    public:
        Student()
        {
            cout << "constructing student" << endl;
            semesterHours = 0;
            gpa = 0.0;
        }

        // ...other public memebers...
    protected:
        int semesterHours;
        double gpa;
};

int main()
{
    cout << "Creating a new Student object" << endl;
    Student s;

    cout << "Creating a new object off the heap" << endl;
    Student* pS = new Student;
}
lewashby 56 Junior Poster

I use firefox from Linux and Firefox keeps dropping my downloads, I don't know if this issue is specific to the Linux version or not. Is anyone else having this problem? Also, I looked through the settings but I don't see an option to limit the number of downloads that run at one time, does anyone know if this is poissible? Thanks.

lewashby 56 Junior Poster

I'm not a professional programmer by any stretch of the imagination so here are my novice thoughts for what they are worth. I've played around with VS a few years ago but I found it's vast array of options daunting and I also realized that it makes you dumber when it comes to understanding what's actually going on from source code to binary. I eventually had to slow way down on my programming practice and learn the Linux OS which is a decision I don't regret. After getting a decent grasp of Linux I began looking for VS like equivalent for Linux (CodeBlocks, Eclipse, etc...) and finally realized that that's not the Linux way, not to mention they also suffered from the same problems that plagued VS. So I started learning the Linux tools of the trade and I took a udemy course on VIM, learned a little gcc, g++, & gdb. I haven't looked back and if you follow the same path I don't think you'll miss microshaft.

lewashby 56 Junior Poster

I'm trying it.

How the heck is root getting 'Permission denied'?

mint-desktop ~ # kill $(/var/run/mysqld/mysqld.pid)
-su: /var/run/mysqld/mysqld.pid: Permission denied
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
lewashby 56 Junior Poster

Nope

garrett@mint-desktop ~ $ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

This all happened after one adjustement in the myphpadmin settings!!!

lewashby 56 Junior Poster

Now I've went a step further. I uninstalled phpmyadmin and I made a point to delete the /etc/phpmyadmin directory to be sure no old settings were still around and yet I'm still having the same problem.

Error #1045 Cannot log in to the MySQL server when I try to sign in with a password &
Error Login without a password is forbidden by configuration (see AllowNoPassword) without a password

lewashby 56 Junior Poster

I placed that line in my /var/etc/phpmyadmin/config.inc.php and now I'm getting a syntax error when I try to load phpmyadmin. I can click on pretty much anything and the error goes away but it still wont let me in.

lewashby 56 Junior Poster

Linux Mint

I logged into phpmyadmin and set the password option to 'no password' and now I can't log in. If I enter the password I was using I get this error
-> #1045 Cannot log in to the MySQL server and if I don't user a password at all I get this error.
-> Login without a password is forbidden by configuration (see AllowNoPassword) Any ideas on how I get this working again so I can log back in?

One more question about phpmyadmin. If the computer I do my development from is a different computer than the one that's actually running apache and php, which one needs to have phpmyadmin installed on it, the web/php server or the machine I'm developing from.

Thanks.

lewashby 56 Junior Poster

Okay, what will that do? I know when I run tar tvf lessonxx.tar on my tar files that it does list everything inside so it seems to be creating a tar fall will everything I want inside. I'm just wondering about that omitting ../ output.
Gribouillis, you're the other user who's always answered a lot of my posts. Thanks.

lewashby 56 Junior Poster

I'm not running this command from /, or as root. I'm trying to backup the web project that I'm doing from the onine udemy class and it's stored at /var/www/html/udemy/php-oop/gallery/ inside that directory I have a backup directory where I'm trying to store all of my tar balls of the web project as I progress through the lessons and making changes to the project. /var/www/html/udemy/php-oop/gallery/backups/ I want to tar everything under gallery except the backups directory itself. I ran the command tar --exclude-tag-all=backups -cf lesson21.tar ../* from inside the backukps directory that's under the gallery directory. And to get the exclude option to work I created an empty file inside backups directory called, well backups. I'm suing relative paths with this command ../ .
So do I have anything to worry about using relative paths in this sense or from the tar output mentioned above? Thanks rubberman. I thank you've answered more of my questions here on Daniweb than most of my replies combined.

lewashby 56 Junior Poster
garrett@mint-desktop /var/www/html/udemy/php-oop/gallery/backups $ tar --exclude-tag-all=backups -cf lesson20.tar ../*
tar: Removing leading `../' from member names

I have an empty file called backups in my backups directory to keep the tar file from trying to backup itself. Does anyone know why I'm getting this output?

-> tar: Removing leading ../' from member names Note that there was a backtick between leading and ../ .

lewashby 56 Junior Poster

Using try/except was on my todo list but I don't have any experience using error/exception handling. Thanks cereal it's mostly working now.

lewashby 56 Junior Poster

In reality both code files are using the same database and table, same version of php on the same computer.

GOOD

$sql = "SELECT full_name FROM inmate_board WHERE tdoc_number =".$tdoc;

        foreach($connection->query($sql) as $row)

/GOOD

BAD->PHP Warning: Invalid argument supplied for foreach()

    $sql = "SELECT full_name, tdoc_number, race, facility FROM inmate_board WHERE type = COURT";

    foreach($connection->query($sql) as $row)

/BAD

lewashby 56 Junior Poster

Thanks I'll give that a try. I'm not actually using a '#' in my code. I just didn't want to post the actualy code because it's for my State's correctional DEPT. I just didn't understand why the foreach loop worked with that same argument in my test code but not in my development file.

lewashby 56 Junior Poster

This is the code I wrote at first and it's working with any problems. But when tried the same thing with my newer program I'm getting the error 'Invalid argument supplied for foreach()'. Again the program below works just fine. Any ideas?

<?php
    // 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();
    }
?>

<html>
    <form method='post' action="">
        Please Enter Customer id# <input name='id' type='text' /> <input type='submit' />
    </form>
</html>

<?php
        $id = $_POST['id'];
        echo $id;

        $sql = "SELECT full_name FROM customers WHERE id# =".$id;

        foreach($connection->query($sql) as $row)
        {
            print $row['full_name']."\n";
        }
?>
lewashby 56 Junior Poster

The php/html file I am working on is laid out in this way.

<?php
  // connect to DB $connection
?>

html
html
html

<?php
  foreach($connection-query($sql) as $row)
    do stuff
?>

I'm getting the error 'Invalid argument supplied for foreach()' when I run this page. Can I not break out of the php and go into html and then come back to my php using the $connection variable created in the upper php code? Or once I break out with ?> is that it, all variable can not be picked back up again futher down in the page?
I can't think of another reason because I have used that exact foreach loop in another file and it worked fine.

lewashby 56 Junior Poster

I placed all the .hpp files in /usr/local/include/ and everything seems to be working just fine. I also placed all the .so.x.x files in /usr/local/lib/ but they don't seem to have any affect on compling/linking. I can take away all permissions to the .so.x.x files in /usr/local/lib/ and my programs compile & link just fine. But if I change the permissions or place the .hpp files in /usr/local/include/ in a sub directory I start getting ld errors when compiling.
Trying to understand all this stuff with library files both static and dynamic as well as object files and header files is starting to make my head hurt. Can anyone clear this up for me? Thanks.

lewashby 56 Junior Poster

Linux Mint 17

I have recently download the SFML library but I don't know where to put the files. There is a lib directory and an include directory. The lib directory appears to have a lot of sym links in it.

garrett@mint-desktop ~/Desktop/SFML-2.3.2/lib $ ls -l
total 904
lrwxrwxrwx 1 garrett garrett     20 Oct 27 17:10 libsfml-audio.so -> libsfml-audio.so.2.3
lrwxrwxrwx 1 garrett garrett     22 Oct 27 17:10 libsfml-audio.so.2.3 -> libsfml-audio.so.2.3.2
-rw-r--r-- 1 garrett garrett 144296 Sep 11 06:40 libsfml-audio.so.2.3.2
lrwxrwxrwx 1 garrett garrett     23 Oct 27 17:10 libsfml-graphics.so -> libsfml-graphics.so.2.3
lrwxrwxrwx 1 garrett garrett     25 Oct 27 17:10 libsfml-graphics.so.2.3 -> libsfml-graphics.so.2.3.2
-rw-r--r-- 1 garrett garrett 366128 Sep 11 06:40 libsfml-graphics.so.2.3.2
lrwxrwxrwx 1 garrett garrett     22 Oct 27 17:10 libsfml-network.so -> libsfml-network.so.2.3
lrwxrwxrwx 1 garrett garrett     24 Oct 27 17:10 libsfml-network.so.2.3 -> libsfml-network.so.2.3.2
-rw-r--r-- 1 garrett garrett 142096 Sep 11 06:40 libsfml-network.so.2.3.2
lrwxrwxrwx 1 garrett garrett     21 Oct 27 17:10 libsfml-system.so -> libsfml-system.so.2.3
lrwxrwxrwx 1 garrett garrett     23 Oct 27 17:10 libsfml-system.so.2.3 -> libsfml-system.so.2.3.2
-rw-r--r-- 1 garrett garrett  74184 Sep 11 06:40 libsfml-system.so.2.3.2
lrwxrwxrwx 1 garrett garrett     21 Oct 27 17:10 libsfml-window.so -> libsfml-window.so.2.3
lrwxrwxrwx 1 garrett garrett     23 Oct 27 17:10 libsfml-window.so.2.3 -> libsfml-window.so.2.3.2
-rw-r--r-- 1 garrett garrett 186008 Sep 11 06:40 libsfml-window.so.2.3.2

And here is the contents of the include directory.

garrett@mint-desktop ~/Desktop/SFML-2.3.2/include/SFML $ ls -l
total 56
drwxr-xr-x 2 garrett garrett 4096 Oct 27 17:10 Audio
-rw-r--r-- 1 garrett garrett 2095 May  8 06:49 Audio.hpp
-rw-r--r-- 1 garrett garrett 5342 Sep 11 06:37 Config.hpp
drwxr-xr-x 2 garrett …
lewashby 56 Junior Poster

When I try to compile the program below in Eclipse I get two erros, ‘const class Fraction’ has no member named ‘n’ & ‘const class Fraction’ has no member named ‘d’
When I compile it on the command line with g++ -Wall FloatFraction2.cpp Fract7.cpp -o FloatFraction I get more errors than I care to look at. I copies this code straight from my book (C++ Without Fear 2nd Edition) so I don't understand why it wouldn't work.

FloatFraction2.cpp

#include <iostream>
#include "Fract.h"

using namespace std;

class FloatFraction : public Fraction
{
public:
    double float_val;

    // Inherifted constructors: with C++ 0X,
    // these can all be replaced with using Fraction::Fraction
    FloatFraction() { set(0, 1); }
    FloatFraction(int n, int d) { set(n, d); }
    FloatFraction(int n) { set(n, 1); }
    FloatFraction(const FloatFraction &src) { set(src.get_num(), src.get_den()); }
    FloatFraction(const Fraction &src) { set(src.get_num(), src.get_den()); }

    void normalize();       // overridden
};

void FloatFraction::normalize()
{
    Fraction::normalize();
    float_val = (double) get_num() / get_den();
}


int main()
{
    FloatFraction fract1(1, 4), fract2(1, 2);

    FloatFraction fract3 = fract1 + fract2;
    cout << "1/4 + 1/2 = " << fract3 << endl;
    cout << "Floating pt value is = ";
    cout << fract3.float_val << endl;
}

Fract7.cpp

#include <iostream>
#include <stdlib.h>

using namespace std;

class Fraction
{
private:
    int num, den;

public:
    Fraction() { set(0, 1); }
    Fraction(int n, int d) { set(n, d); }
    Fraction(int n) { set(n, 1); }
    Fraction(const Fraction &src);

    void set(int n, int d) { num = n; den = d; normalize(); …
lewashby 56 Junior Poster

Setting up something in my home is not an option. When I was young our house burned down so my back need to be outside of my own house. Now, how and why would setting up a NAS violate my ISP's terms of service?

lewashby 56 Junior Poster

Are you asking a question?