Jump to content


gizmola

Member Since 06 May 2003
Offline Last Active Nov 20 2017 07:02 PM

#1553590 Building a CMS

Posted by gizmola on 09 November 2017 - 02:19 AM

There is no magic to it, it's javascript/ajax.

 

With that said, in the last few years, javascript frameworks have developed a tremendous amount of momentum.  Essentially this moves a lot of the code from the backend into a client javascript application.  Typically the backend becomes an api providing access to data via REST or SOAP.  I don't see a lot of people using SOAP anymore.

 

Wordpress has been all in on the use of ReactJS, even to the extent that they announced they would abandon its use due to Facebook's plan to utilize a BSD + Patents license.  Ultimately, Facebook bowed to the pressure and threats to abandon it and changed the ReactJS license to MIT.

 

At any rate ReactJS, Angular, Ember, Vue etc. are all quite prevalent in the current web development world, and provide the sexy interactive UI you are talking about.  The underlying technology that anchors all of these technologies is still Javascript/Ecmascript and Ajax which facilitates actively changing the UI without having to GET/POST the entire page and rebuild it from scratch.




#1553104 storing data with a ORM - a first approach

Posted by gizmola on 27 October 2017 - 04:07 PM

You have a file that has lines of data in JSON format.  However it is not a complete JSON structure, so you will need to read it in line by line:

 

 

 
with open('file') as f:
    for line in f:
        data = json.loads(line)
        # Now assign values from data to your mysql fields and save row



#1552627 How to reconcile constants in code and in database

Posted by gizmola on 10 October 2017 - 10:35 PM

I do the same as Kicken in most cases.  There are exceptions, where there is some significant benefit to having a static database lookup table.  If there is a way for the system to function purely through the addition of new lookup values, and not requiring code changes, then having the lookup table is great.

 

Alternatively, there are times in the past where I will utilize a lookup table using what I call a 'code' primary key.  This is typically a CHAR[1] with an associated name.  This does have some human readability advantages when looking at a raw table, if the codes are fairly clear.  In your example:

A| Active
I | InActive
B |Banned 
etc.

Make it easy to remember, and easy to look at the values in the user table and tell what is going on.  Since a char[1] is highly efficient use of storage, there's no big overhead cost or loss of functionality.    Sometimes people who don't know better think the only Primary keys they can or should use, should be integers with auto increment.

 

The other issue that gets brought up is the cost to read in those database values on a regular basis which is very wasteful.  People should be using caching solutions like memcached or Redis to avoid that overhead, if you choose to go that direction.




#1552612 Getting timestamps of period boundaries

Posted by gizmola on 10 October 2017 - 06:27 PM

I think that people are responding to your original question:

 


Creating a class to find the start and end time stamps of various periods.  

 

Very hard to understand what you mean here.  Programming has lots of jargon, and what I have found over the years is that the precision of your terminology within the specific domain you are investigating is important.  For example here, you have "start and end ... time stamps".  Then you add "various periods."  It's unclear where you are going.  

 

A "timestamp" has specific meaning within mysql, for example, as it's a column datatype you can use.  Like many things that seem simple on the surface, you can really dig into an implementation and find complexity.

 

Then of course there are unix timestamps.  Depending on what you are trying to do, working with a unix timestamp might be good.   For the most part, I find myself using php Datetime objects if I have the need to deal with datetime like values.  With that said a "time period" can be defined to be within a pair of timestamps.  You could also start with either a begin or end timestamp, and given a "time period"  which would be more precisely understood if you called it a "duration", "interval" or "Date Interval"  which is the specifc class that you use with the php Datetime class to do datetime arithmetic. 

 

The point here is that what you are trying to do -- not to mention "the why" is entirely missing.   

 


strtotime() seems so amazing some of the time but quirky others.  Likely it is mostly user operator but I've read of some gotchas. 

 

Highly vague statement.  If you read something, a link to what you read would help, don't you think?  Otherwise what use is this aside?

 


Think I should use mktime() as I do so in my year boundary class?  Or some other strategy?  Thanks

 

Now we get to your actual question, such as it is.  Then you follow up with a bunch of uncommented code that we are I guess supposed to read and ponder on your behalf.

 


PS.  Should I be using an instance class?  If so, why?

 

What is an "instance class".  Can you provide a definition or link to what you are talking about?  This is not standard terminology for OOP, PHP or any language really.  There are classes which are essentially blueprints for objects, and then there are objects which are sometimes referred to imprecisely as a "class instance", but in no way is "instance class" a phrase that will be clear to anyone or relevant.  It is not an alternative or a direction or a specific implementation.  Are you talking about a "singleton" which is an object oriented design pattern that tends to be used to solve certain problems.  I'm not sure what you are actually asking about, and I doubt anyone else is either.

 

I think it's great that you are intellectually stimulated by programming, and find this a community that is likewise interested in the same topics you are.  There are plenty of people who come here just to try and weasel out a free fix for some php software they can't be bothered to understand.  This community was built with people like you in mind, but what I've noticed in your interactions with people here, is that you would benefit greatly from taking some more time to think about and articulate your questions, and to be a lot more precise with the terminology you employ. 

 

It tends to be that, you might understand PHP OOP classes very well, but in your mind think of them as "cogs" because that works for you.  The problem is, that you can't drop a question here and start asking:  "So my cogs are not swishy the way I like them to be, do I make them more or less swishy"  and not expect to find annoyance, frustration or outright hostility from the people who spend lots of their free time trying to help people like you out.  If you would work on making sure you have clearly articulated and well focused questions, illustrated with self contained code snippets, along with an improved use of appropriate technical terminology, I think you'll find this more effective, and any responses you receive will reflect an appreciation of your efforts and a respect for you as a community member.




#1552378 How to escape Ajax Request in PHP

Posted by gizmola on 04 October 2017 - 10:38 PM

Yes.




#1552345 aws elastic beanstalk permissions and ownership.

Posted by gizmola on 04 October 2017 - 05:05 PM

The webapp user doesn't need to belong to the apache group if apache is running as webapp.  All the ownership should be fine.




#1552167 aws elastic beanstalk permissions and ownership.

Posted by gizmola on 30 September 2017 - 03:58 PM

You are running shell scripts that set environment variables for some reason. Maybe these are ubuntu things, but they aren't important to the basic workings of the system unless there is something happening in the apache startup script. I personally use amazon linux for all my ec2 instances, since they insure it works well with ec2 and they come preconfigured with package repos maintained and tested by amazon.

At any rate, what I feel is the best practices in this situation is that you have a separate user|group combination for apache. However, apparently that is webapp currently, so I would not look into trying to change it. Check your apache httpd.conf file (should be somewhere in /etc or a directory underneath it) and see who the user/group is.

To check out the entry for webapp, cat the /etc/passwd file and see what the entry for the webapp user is. I don't know why there wouldn't be a group there.

In the apache httpd.conf file there is an entry for the user/group apache will run as. That should be webapp in this case.
 
User webapp
Group webapp



#1552143 aws elastic beanstalk permissions and ownership.

Posted by gizmola on 29 September 2017 - 08:10 PM

ec2-user is a standard user for ec2 instances. You should not use that user for anything, as it is essentially root equivalent. What I mean by that, is that user is setup with the key for the instance, and is able to sudo without a password.

With EB, the user who owns your php app is indeed webapp. Once you get into your instance you can change to that user from ec2-user using sudo su - webapp and tweak permissions if you must.

In summary, you should not attempt to change the file ownership of your project. That is managed by EB. If you need to tweak a directory perm, su to webapp.


#1551979 Error 500

Posted by gizmola on 26 September 2017 - 08:56 PM

You should check your server logs. They will have some information pointing out what the problem is. cyberRobot's solution will work sometimes, but I always start with the logs as there are many things that can cause 500 errors that have to do with basic configuration of the vhost, and directory and file permissions.


#1549896 Table not updating on webserver mysql 5.5

Posted by gizmola on 18 August 2017 - 05:57 AM

I edited your post to add code tags, and in the process I inadvertently seemed to have lost your error message. Mea Culpa in advance...

With that said, we are on shaky ground when you make statements that are completely false.  There is no way this code worked:
 
$query = "USE hypnotherapy; INSERT INTO weight_management VALUES " . 
"('$email', '$fname', '$lname', '$address', '$pcode', '$children', '$cnames', '$c_age', '$doctor', '$where_refer')";
Mysql does not allow you to batch sql statements.


The "use" of databases is accomplished when you connect. You will use the database you specify in your connect statement. There is a way to change the currently selected database, but there is no reason for you to need that in your script. You simply can't add it to the front of your sql statement and pass it. That is not allowed with the mysql api.

As Psycho pointed out, the insert statement is also missing the column list. Can you get away with no column list? Yes, but only if your number of values exactly matches the number of columns in the table.

Few people will take advantage of that fact, as it's poorly documented at best. If indeed that is an exact match for your column list, then your weight_management table apparently has no obvious primary key. Every table should have a primary key, ideally an UNSIGNED INTEGER AUTO_INCREMENT.

If the column list doesn't match, then the insert statement is going to fail with an error like: "ERROR 1136 (21S01): Column count doesn't match value count at row 1"

Again unfortunately I lost your error text. If you want to post a follow up, I'll restore it to your original question.

What I'd suggest in the meantime is fix your sql statement at the very least. Something like:

$query = "INSERT INTO weight_management (col1name, col2name, col3name...etc) VALUES ('$email', '$fname', '$lname', '$address', '$pcode', '$children', '$cnames', '$c_age', '$doctor', '$where_refer')";



#1549854 Can a saved vagrant box handle a change in ISP ?

Posted by gizmola on 17 August 2017 - 05:11 AM

What you want to do is change your network from public_network to "private_network". This will used the Nat adapter.

Make sure the network is something that is unlikely to conflict with your home or work network. Something like '192.168.77.x'


#1549188 what to do now ?!

Posted by gizmola on 02 August 2017 - 09:40 PM

Learning to program can easily become a rabbit hole.

Programming exists to create applications and systems that solve a problem or facilitate a business.

The simple answer is, in order to progress as a programmer you need to actually program.

Write down a design specification for something you want to build, and build it. Along the way you will need to problem solve. You will need to learn things you don't understand adequately at present, and you will fail, and in the process learn how to debug and become more competent.

Let's say you read a bunch of books on carpentry, but never try to build anything? Would you hire that person to make you cabinets for your house?

I know many developers who are starting out, who build things simply to have a portfolio showing what they can do.

When I first started as a programmer, I made some silly applications that didn't do much, but in each case I learned a great deal. Eventually I created a freeware menu system (this was back in the days when DOS PC computers dominated the marketplace) and my software allowed you to create some simple text files that would be read in, and allow a user to navigate through the options and start programs. There were many such programs available at the time, but I built mine anyways, and used it on my computer and installed it on my parents computer.

In creating it, I realized that I had a need to utilize record structures, linked lists, windowing libraries and file io. It required me to learn a lot of things and as a result I advanced as a programmer and this experience lead directly to a job that essentially started my professional programming career.

With each project you learn more and become a more capable developer.


#1549062 deploy a database to the aws server

Posted by gizmola on 30 July 2017 - 08:39 PM

All the cool kids use Docker or Kubernetes these days. Might want to check them out as an alternative.

I do have to question the idea of an app server + DB monolithic stack. That is not the typical way that a scalable application is created.

Usually you have 1 -> n app servers per db, so you need an architecture to facilitate that. To start out with a plan that involves a DB on localhost per app server glosses over all the issues that your production architecture will have.


#1548708 PHP Contact form (Help, please)

Posted by gizmola on 22 July 2017 - 05:48 AM

Well, it's all in French.

Kind of a loaded question... Are you having problems?

I will say that you're not validating $name and $email adequately enough to prevent a malicious user from hijacking this form and crafting their own email messages to anyone they want, with any content they want.


This is great feedback, but useless for a novice if you aren't willing to pull out some specifics or help them figure out how to do it properly.


#1548641 Please explain "FOR" loops

Posted by gizmola on 19 July 2017 - 06:49 PM

There are times when attaching the "i" has worked and times when it doesn't. The last time I tried this, I thought it would echo a string 10 times but what it actually did was echo ten letters of the string. I just don't know understand the difference between the two. Can someone explain this to me please?


For loops are just generic conditional control structures. The php syntax was borrowed from c, and it's common to many languages.

In your example there's a problem because all php variables have to start with a '$'. But if we forget about that for a second, and just consider your question, here is what happened.

What you wanted (echo a string 10x)
 
$myVar = "This is awesome";
for ($i = 0; $i < 10; $i++){
   echo $myVar . '<br>';
}
What you did:
 
$myVar = "This is awesome";
for ($i = 0; $i < 10; $i++){
   echo $myVar[$i] . '<br>';
}
What is happening then? In this second case, what you are asking php to do, is to try and transform $myVar into an array from a string.
PHP is happy to do this for you, as it already considers a string to be an array of characters.

So what your code does is echo a single character from the $myVar string each time, and since $i is being incremented you get this:

$myVar[0] .. then $myVar[1] .. then $myVar[2] etc. until the loop condition becomes false. In your example, it will loop 10 times, or up to 10 letters of the string: from $myVar[0] - $myVar[9].

The loop itself is going to repeat the individual instructions contained within the control structure -- { ... } until the condition becomes false. With "for loops", you just have some place holders for built in variables that it will initialize, and increment or decrement each time the loop is entered.

In other words, the $i is something that you may or may not want to be using inside the loop, but it's not required. Just to echo 10 strings, there is no need for you to reference $i inside the loop at all.