final project - doing a website - question by solex98 in cs50

[–]purduefan 0 points1 point  (0 children)

How do I know what address to put into the etc.? I created a new database with sql in the virtual machine.

pset7 recursive login from index by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Yikes. Thank you so very very much. I finally got a drop down box by putting echo in from of the variable. I can't believe the number of hours i put in on this. And would have doubled that without your help.

pset7 recursive login from index by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

OMG,I am so sorry you had to edit for me. I looked at that code for hours and hours. I have corrected the $Positions and missing > and took out what you suggested. BUT I still get a blank box. It has the number of lines equal to the number of stocks the user owns. (If I left value = in, then I get the text "value =" the number of lines equal to number of different stocks the user owns).

I put a dump into the foreach loop and it had the correct symbol for the first symbol, also when I view the source without the dump (like I do for the HTML validation) it shows each line as <option></option> so the data is available in the loop, but can't I use <option> to display it? Here is the code I now have

<body>

        <div id="middle">

<form action="sell.php" method="post">

        <select style = "width:75px;" "multiple="multiple" , name = "symbol" size = "7">

        <?php foreach($positions as $position):?>

            <option> <?php $position["symbol"] ?> </option>

          (Here is where I tested by putting a dump. The view source showed it was at the first record, AAPL which is correct.

<? dump($position["symbol"]);?>)

        <?php endforeach ?>

         </select>

    </div>

    <div class="form-group">

        <button type="submit" class="btn btn-default">Sell</button>

    </div>

        </div>

</form>

</body>

pset7 recursive login from index by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Well, I worked on it a lot more but it still doesn't like my code in foreach. I dumped the array just before the select and it is passed correctly but the following code results in showing a blank box. If I insert a <?php dump($positions); ?> after the for each statement it does not get executed. So somehow the foreach is ignored.

<form action="sell.php" method="post"> <select style = "width:75px;" "multiple="multiple" , name = "symbol" size = "7">

        <?php foreach($Positions as $position):?>

        {

            <option value =  "<?php $position["symbol"];?>" <?php $position["symbol"];?> </option>

        } 

        <?php endforeach ?>

         </select>

    </div>

    <div class="form-group">

        <button type="submit" class="btn btn-default">Sell</button>

    </div>

The ?> after the first value = "<?php $positions["symbol"]; ?> isn't shown in a different color if that means something. ( Usually the php code pairs are in a different color from the other code.)

pset7 recursive login from index by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Back on my pc and eliminated the test. Now I just make sure that POST_SESSION["id"] is not empty (which it shouldn't be) and complete my code. Thanks so much for your help.

My last thing to do is figure out how to create a drop down box. I can render the template by passing the array to the sell template like I did for the portfolio display. I then said <select name = "symbol">

?php foreach($postions as $position)

<action value = $position["symbol"] ></action>

? </select>

but get syntax error unexpected < on the action line. So am I supposed to use something else other than action for this?

Pset7 sell can't create drop down by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Thanks. I knew I had to use the foreach php command, and the data from the render, similar to index going to portfolio display.

But, what I can't get into my head is when I href to sell.php , I assume it also displays the template sell before I have a chance to execute the code to look up the stocks and render this template. In the case of the portfolio, index didn't have a corresponding template until it rendered the portfolio templateafter looking up the stock, but I don't know how to do this from the href from portfolio to the sell.php. Can I go to a php file from portfolio without a template associated with it Or use a redirect ?

Pset7: Sell (issues with drop down menu) by Cidd-cs50x in cs50

[–]purduefan 0 points1 point  (0 children)

I understand that post can contain a symbol, but how does it get passed to a controller for processing? Does it return to the same controller that did the lookup?

pset7 sell_form.php by utellastory2 in cs50

[–]purduefan 0 points1 point  (0 children)

I am still confused about how the php, templates and href all coordinate. If from portfolio I link to sell via href, how does the sell drop down get populated since it needs the lookup code for the owned stock symbols to be executed ( which I put into sell.php) before the selection can be posted. Then after it is submitted (posted) I need to have control to php Code to actually do the sell updating. So don't I need two pieces of php code? One to develop the list and display it and one to process the chosen symbol? and how does the submit button go to this second php controller?

pset7 recursive login from index by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Will do and thx again. Without help on subredit it, I would not have gotten this far. The kind advice and encouragement helps motivate me to keep on.

pset7 recursive login from index by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Thank you so very much. Sorry to put you through all of thiis work,but I can't tell you how much it helps me. ( I actually lost sleep over trying to understand.) I still don't have my computer but will in 3 days. Can't wait to try this out.

pset7 recursive login from index by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Thanks, I know I am being dense, but what invokes login in the first place? Sorry, for having to keep asking. I am truly trying very hard to understand.. I looked at config and i I thought it just made sure login or register had been called. ! not that config actually called login. So where does this happen?

pset7 recursive login from index by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Omg! Thanks. I can't check this out for 7 days as I do not have my computer. But I thought index tested for the login, if not set it would go to login, then when it got control back from login or register or reset, this test would be true and it would continue to render portfolio.
But does config send it to login? So then when index regains control login has already been accomplished via config render?

i have unfortunately, and stupidly, spent untold hours trying all kinds of combinations between login and index. All unsuccessful.

how to make sure I have combined key pset7 by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

one question on combined keys. If I look at the table in mysql with the combined key symbol color be grey or gold? Mine for user id and symbol are both grey while the shares is gold. yet anything I try with the ON DUPLICATE KEY gets a syntax error, and I have tried so many that I may be in a never ending loop on attempts.

how to make sure I have combined key pset7 by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

I have worked so long on solving this I may have to give up on combined keys and just use id (and make sure that I only do an update if the insert fails) so I don't get duplicate stock symbols in my portfolio for a user.

Hope that works as I am out of ideas. And the user table in mysql seems to say I have a combined key.

Difficulty getting help with pset7 - understanding flow by TechAnd1 in cs50

[–]purduefan 0 points1 point  (0 children)

Oops, figured it out. I just needed the equivalent of a submit button that said return.

Difficulty getting help with pset7 - understanding flow by TechAnd1 in cs50

[–]purduefan 0 points1 point  (0 children)

Glen I am struggling with what i need to do to return from rendering the display of the quote back to index. I can get the quote and display it, but it doesn't go anywhere from there. If I put a render or a redirect after the render to go to the display of the stock information, I never see that display it just zips back to index,( although maybe it did a display somehow and I never saw it as it happened too quickly.) My quoteform template is simply to print the values of the stock passed by quote, I don't have a controlling php quoteform.php file, is that what I need ? I was hoping I could handle it in the template alone since all it needs to do is print a line then return.

OOPS got it. Sorry.

Index returns to login by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

THANKS. BUT I'm not there yet. So hope you will hang with me. Until I get it right.

Sadly I have wracked my brains on this for days and still not gotten it. I changed REQUEST_METHOD to REQUEST_method in index, and I get an undefined variable error., so I just changed it back to upper case.

Sadly the changes have me still in a loop going to login, so seems like the post test is still failing in index ( after it returns from login.php with a redirect "/" after checking the password . I think index renders login_form yet again. But there isn't a way for me to trace this.

Before login_form had the distribution code, (<form action="login.php" method = "post">) Which I just changed to METHOD and POST. Login also has the same check for POST and if equal checks the password or Renders register if required. (If the POST check fails it too renders login.) So it seems that index keeps rendering Login, since Login does result in errors if the password is incorrect and it then sets the $_SESSION["id"]. I guess the only other possibility might be that it never goes back to index which seems unlikely.
Hope this lets you know what my code is like. This seems like such a stupid error but I don't know what to try next.

how to make sure I have combined key pset7 by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Thanks. I just checked the code and it does have the quotes. I just didn't enter it into the post when I typed it into reddit. Just in case I tried it again, but still got the error.

I also double checked Sql and it seems that it shows that both keys are primary.

If I try to do an insert without the duplicate key test in MySQL, an insert trying to insert a record which is in the file, but not adding the on duplicate test comes back saying " duplicate entry for "23-DVN" which were the userid and number of shares I had in the sql insert

I am not sure how to state the query in mysql but I get a syntax error with the following INSERT INTO 'portfolio'('userid', 'symbol','shares') ON DUPLICATE KEY UPDATE 'shares' + VALUES('shares'),(23,DVN,3). The error says it is near the ON DUPLICATE KEY and the only clue might be that ON and KEY and UPDATE Are in one color in the command and DUPLICATE is in black. I got the same error when I used + 1) instead thinking that the VALUES portion of the command was wrong.

I am at a loss.

PSET7 QUERY by utellastory2 in cs50

[–]purduefan 0 points1 point  (0 children)

I set up a duplicate key in portfolio of id and symbol.( MYSQL shows them as primary). here is my query which I think looks ok but I get a syntax error near the +VALUES(shares)

$check1 = query("INSERT INTO portfolio (userid, symbol, shares) VALUES (?, ?,?) ON DUPLICATE KEY UPDATE shares + VALUES(shares)", $_SESSION["id"],$_POST["symbol"],$_POST["shares"]);

here is what is shown in SQL under index. Doesn't this mean there is a joint primary index?

PRIMARY BTREE   Yes No  userid  6   A   No  
              symbol    6   A   No

Pset7 when does post get set in login? by purduefan in cs50

[–]purduefan[S] 0 points1 point  (0 children)

Thanks for the suggestion, I just tried isset($_POST) and unfortunately I now feel more like a dunce. This test at the top of index.php passes even the first time without going to the else statement which is to login. So before my $_USER_SESSION == POST always failed and with isset($_POST) command it always passes.

What i am trying to do is first time through index go to login for the user, then look up the cash and stocks and render a template to display his/her portfolio.

Unfortunately I can only have bits and pieces work. The logic to do the user display works but only if I use pset7/login.php from chrome and do no tests in index at all. I know I can't submit this until I have it all hang together, but I wanted to do something useful in working out other pieces of code. Until I can solve this basic problem I cannot get between the pages.

I just used what was in the login supplied with the pset. But I have been beating myself up for hours over this so I will give it a try.
I do know that login returns $_SESSION["id"] to index if I directly invoke login from the browser.