Hot answers tagged

4 votes
Accepted

CS50 PSET7 Finance: in SELL; expected to find select field with name "symbol", but none found

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 ...
user avatar
4 votes
Accepted

Cannot get drop down menu to display for pset7. Why would this be?

The request method is GET by default. When the user visits http://pset7/sell.php, she is requesting the page (i.e., sell.php in this case) using GET. Therefore, the condition $_SERVER["REQUEST_METHOD]...
user avatar
  • 17.4k
2 votes
Accepted

Pset7 undefined index

the notice tells you what exactly the problem is -- there's no index called "shares" in stocka. recall that query returns an array of rows, even if the result was a single row, in which case it would ...
user avatar
  • 17.4k
2 votes

pset7 sell.php doesn't sell stocks or change cash

if you look at your sell_form.html, you will find that at this line <option value="symbols"><?= $total["sellsymbol"] ?></value> you have an attribute value set equal to "symbols" ...
user avatar
2 votes
Accepted

How to create a drop-down menu that contains the stocks that has as options?

First, for closed tags, if you open a tag, you should close it. I see you're not closing the <select> tag. More information about that tag maybe found here. Also, you have </div> within ...
user avatar
  • 17.4k
1 vote
Accepted

pset 8 finance: :( sell handles valid sale

check50 is looking to see that if you bought, say, 5 shares of ABC and then sold 3 shares, your index page will show the remaining 2 shares with a value using the current quote. (since that is what ...
user avatar
  • 18.4k
1 vote
Accepted

pset8 finance: Problem with calculaton for "/sell"

I suspect you copied buy.html to create sell.html form. I also suspect the form action was not updated to "/sell". The first query in the "strange" does not exist in this sell function. It would ...
user avatar
1 vote
Accepted

PSET7 Finance- Quote and Buy not passing all checks

Your guess: is that it has something to do with a rounding error as it is looking for a specific number. is probably right. Usually using the 'usd' function in helpers.py will fix that right up....
user avatar
1 vote
Accepted

Pset7 Sell stockprice not a bound parameter

You forgot the : for :stockprice in VALUES (:userID, :symbol, :shares, :amount, stockprice). And to quote Cliff B: If this answers your question, please click on the check mark to accept. Let's ...
user avatar
1 vote
Accepted

after using style50 and correcting my spaces etc I ran my code again and got this error which makes no sense to me. need some help please?

Problem is with line db.execute("INSERT INTO history(symbol, shares, price, moment, id) VALUES(: symbol, : shares, : price,: moment, : id)", symbol=info["symbol"], shares=shares, price=usd(info["...
user avatar
  • 20.7k
1 vote
Accepted

problem , yet again in pset7 . my sell page works fine but check50 shows me something else O.o

Those errors all mean that there's an earlier test that failed and has to be corrected before the remaining tests can run.
user avatar
  • 64.1k
1 vote

pset 7 sell Type Error 'NoneType' object

Your guess is correct: the lookup function isn't finding symbol. The problem is here <option value = "Symbol">{{ stock.symbol }}</option></option>. "symbol" will always have the ...
user avatar
1 vote
Accepted

pset7 sell: can not make drop down menu work

Just after I posted a question i got it. I should put all data manipulations under else from request.method == "POST".
user avatar
  • 11
1 vote
Accepted

pset7 sell.php I seem to be missing something

It is right. CS50::query() always returns an array of rows, even when the result is just one row. That's why you should use the [0], as you have correctly done. You can ctrl+F this: // first (...
user avatar
1 vote
Accepted

Pset7 pass data to drop down bottom

The query returns what? An array. From Pic 1, $rows looks like this: $rows[0]["symbol"] = "ATT"; $rows[1]["symbol"] = "MMM"; $rows[2]["symbol"] = "X"; At the foreach in Pic 2, $stocks is an array ...
user avatar
1 vote
Accepted

pset7 unsupported operand types

Maybe the problem isn't $ticker[0]["shares"]; there are two operands in the statement. From the spec: Assuming the value of $_POST["symbol"] is a valid symbol for an actual stock, lookup will ...
user avatar
1 vote
Accepted

sell.php doesn't return error when the stocks doesn't exist in the user's portfolio

// to make sure the stock is in the user's stocks $rows = CS50::query("SELECT symbol FROM stocks WHERE id = ? AND symbol = ?", $_SESSION["id"], strtoupper($_POST["stock"])); if ($rows["symbol"] === ...
user avatar
  • 3,036
1 vote

I am currently working on sell.php. I have debugged the code several times but I am unable to find the error.?

You are using the wrong return value. From the pset specs: If query is instead passed a DELETE, INSERT, or UPDATE statement, it will return a non-negative integer that represents the number of ...
user avatar
  • 1,415
1 vote
Accepted

pset7 sell: MVC problem

Looks like you're mixing up your view and controller, which appear to be sell_view and sell_index, respectively. If so, sell_index should contain all the php code from querying mysql, storing the ...
user avatar
  • 1,415
1 vote

Pset7 - Issue with updating cash in sell.php

In the line $funds = $money[0]["cash"]; you are trying to access first element of $money array. However, $money is not defined as an associative array, it just contains a numeric value.
user avatar
  • 1,415
1 vote

Pset7 Sell.php not adding money to users

To get the price per share, try: $price=$temp_array["price"]; and to get number of shares, remember that query returns an array, and you want the 1st (index=0) row. So try: $numshares=$temp_array2[...
user avatar
  • 1,415
1 vote
Accepted

pset7 sell controller issue: undefined index

This means that $positions array don't have the key value in it. Check isset($positions["value"]) before hand.
user avatar
  • 189
1 vote

Array in php vs R (pset7 sell.php)

Just like _POST your positions is an associative array. Just as you get $_POST["symbol"] you get $positions["price"]. If I understood correctly you want to do something like the following <?php ...
user avatar
  • 7,326
1 vote
Accepted

Pset7 How to Program Popup?

If you want to use the popup window for any browser you probably want to use javascript. The popup window you have above is called a confirmation box. Here is how to use it: function foo() { ...
user avatar
  • 7,326
1 vote
Accepted

sell.php doesn't update cash and does sale of stock does not show up in history

i presume you have got the variable $number from the function lookup. this gives an array of associative arrays, (although there is only one associative array) try $numbers[0]["shares"]
user avatar
1 vote
Accepted

Where is the issue with my sell template?

Try the following <option value="<?= $symbol["symbol"] ?>"><?= $symbol["symbol"] ?></option>
user avatar
  • 17.4k
1 vote

How to Access Values That Are Submitted from sell_form.php to sell.php?

If you're submitting using POST as a method, then you should be able to access the currently selected item in the list from sell.php using something like $_POST["stock"] If you're submitting using ...
user avatar
  • 17.4k

Only top scored, non community-wiki answers of a minimum length are eligible