CS50 course materials will tell you that the permissions need to be set as follows:
chmod 711 for directories
chmod 600 for PHP files.
In general, this is the correct advice.
However, if you have run update50 recently, you should know that there is a bug requiring chmod 640 instead for PHP files.
I've posted this ...
There is nothing in the spec saying to output the purchase price to the user.
That is because such a page is not required.
check50 is parsing your index.html page after it makes one purchase, so it should find the current value of those shares 112.00 and the updated value of cash (10000-112) 9,888.00
If I had to guess, I'd say that you aren't formatting ...
Use hash instead of encrypt in your register function. I tried it, it worked for me. I was able to sign on as an existing user, or register (and sign on as) a new user. I am not advocating blindly using functions without reading and understanding the doc. Except maybe on a beautiful, sunny, lazy, Sunday afternoon :)
To solve this issue, you need 2 variables. Let's call them $userinfo and $cash.
First use query() to get cash value from the row with the id that is contained in $_SESSION. Then use this line of code to put the cash value into $cash.
$cash = $userinfo["cash"];
Then you can put cash in print, and it will print out the user's cash.
I'm not an expert, but apparently it's supposed to be applying MVC. I think the idea behind MVC is dividing the website/web application into 3 interconnected parts.
The model (e.g., the database)
The view (e.g., the files under templates)
The controller (e.g., the files under public)
And the reason behind this, as this article suggests, is to separate ...
Since "stocks" are in one list and "currentprices" are in another list you will get this result when you use two lists and two loops.
One solution would be to use one loop and use currentprices[i] where
i is indexed to the row in the "stocks" list.
Another option would be to add a "price" key to each "stocks" row in
the index() function instead of building ...
Inside the function for the respective routes you can just call the function "flash(message)" before the "return redirect()" function, where "message" is the message you want to display. for example:
SOLVED. I added the following:
shares = int(request.form.get("shares"))
return apology("shares must be a posative integer", 400)
I was under the impression that, since I was receiving the popup error before posting /buy, there was something else causing the problem.
The form has an input element whose name is "symbol". The spec requires a select element.
Require that a user input a stock’s symbol, implemented as a select menu whose name is symbol.
Here is doc on select from MDN.
The last line in the log about errorhandler is a red herring. More on that later; will edit after proper research.
The important line in the log is where it says something about bind parameters (if log was posted as text not image I could cite it here).
This result=db.execute("SELECT * FROM users WHERE username = :username") is not proper syntax.
If lookup() doesn't find the requested symbol, it will return None. That is not explicitly stated in the spec, but that is what the try/except block does in the function.
None is not subscriptable, so result["name"] will give an error in the case that lookup hasn't found a stock.
Since None is falsey, if not result: will evaluate to true if lookup returned ...
According to the docs:
You can use the VALUES(col_name) function in the UPDATE clause to
refer to column values from the INSERT portion of the INSERT ... ON DUPLICATE KEY UPDATE statement. In other words, VALUES(col_name) in
the ON DUPLICATE KEY UPDATE clause refers to the value of col_name
that would be inserted, had no duplicate-key conflict ...
Let's break it down:
I think you can tell that $_POST["shares"] is the variable to be mached and the regex string is /^\d+$/.
The first and last / are the delimiters of the regex, so we are left with ^\d+$.
^ assert start of subject (or line, in multiline mode)
So that marks the beginning of the regex.
\d any ...
The problem is really about host(smtp.fas.harvard.edu),
I had the same problem and here is my decision:
I created a new mailbox at gmail, and used it like this:
/*Sends a message of $body with subject $subj to $to*/
function email($to, $subj, $body)
// create mail object and set some settings settings
$mail = new PHPMailer();
The Apache2 web server in the current version of the appliance needs a configuration tweak. Please run the following commands in a terminal in your appliance:
sudo a2dismod php5
sudo a2enmod suphp
sudo service apache2 restart
Then try again to visit http://pset7/ in Chrome in the appliance.
The post method is only used when you submit a form. Clicking register doesn't count as a post method, therefore you are skipping the entire section of your code in the post conditional, and the code reads the else statement.
You can't use the aggregated value in WHERE. WHERE is applied to the table data, and the aggregated values are created later.
There is the complementary HAVING clause, processed after aggregation. Use that instead. It's placed directly after the GROUP BY part.
Yes your logic is correct, and this is exactly the way the world works.
Say I have $20.
I buy a diamond for $10.
So now I have $10 left.
In a week from now, the same diamond, costs $5.
But I still have $10 left, not $15. My current cash balance is not determined by the value of the things I bought at past. It stays
Now say I also buy this diamond.
A 503 Service Unavailable error is usually a temporary one, as this one turned to be. It usually indicates that the server is either overloaded or undergoing maintenance. The web server is still accessible, as it's able to display the error page, but the website is not.
The best thing to do when encountering this type of error is to try again later.
The menu value is not being correctly assigned in the HTML page. The name of the variable needs to be on the element that you want to access.
In your code, the menu variable name is assigned to the form element.
<form name="menu" action="sell.php" method="POST">
It should be assigned to the <select> tag, since that is the value you want.
From the pset instructions:
Know that index.php is the
file that’s loaded by default when you visit a URL like https://ide50-username.cs50.io/.
...which calls (redirects to) login.php (via config.php) if empty($_SESSION["id"]), which presumably it is when first called.
Recall from the implemention of indexes() in pset6's server, how index.php or index....
Do not use chmod 777 *. That will probably help you to get your site to load, but it is bad for security, and a terrible habit to get into. It's like taking the front door of your house off of its hinges rather than using a key.
I have written about these permission problems in many places already, but the short version which should get you running is to do ...
Do not use chmod 777 views/*. That will probably help you to get your site to load, but it is bad for security, and a terrible habit to get into. It's like taking the front door of your house off of its hinges rather than using a key.
I have written about these permission problems in many places already, but the short version which should get you running is ...