Skip to main content

Questions tagged [sql]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
683 views

CS50 Finance - How to add to cash

I want to make it so the user can essentially add $10,000 to their current balance. To do this, I made a user with id 26 that has $10,000. I want to add user26's funds to the current user's funds to ...
K. Rich's user avatar
  • 11
1 vote
1 answer
382 views

pset7 buy - ON DUPLICATE KEY syntax question

I'm on pset7 buy, and I just need some explanation on how the ON DUPLICATE KEY syntax is supposed to look (at least I assume that's the issue). Btw, id and symbol are both unique keys in my portfolio ...
Scott's user avatar
  • 147
0 votes
1 answer
328 views

pset7 finance app in Python - buy function won't add anything to database!

The code I've written for the parameter checks all works fine, and on clicking the buy button everything seems to work... but then nothing gets added to my database! I've combed through the SQL query ...
StephanieJosine's user avatar
1 vote
1 answer
235 views

pset7 why doesn't my SQL table update?

Can anyone tell me what's wrong with my INSERT INTO? The table is not updating. I get the first purchase and nothing after that. https://gist.github.com/0bc6c50a5f399ed1a672a8a345cbc395 Here is the ...
cfdphd's user avatar
  • 105
1 vote
1 answer
509 views

SQL search multiple columns with priority

I'm trying to implement the search in pset8 and want to find the most elegant and fast solution. The way I have implemented it is to first of all check whether the search term is an int, and if so, ...
Steve Bunting's user avatar
0 votes
0 answers
166 views

How to check if an SQL table exists without relying on errors?

pset7 help pls. Trying to check if a table exists. I am getting the error "information_schema.tables does not exist". I guess information_schema is not there in our SQL version? How else could I ...
Sank Finatra's user avatar
0 votes
1 answer
68 views

Flask column order randomly changes whenever I refresh local host

Whenever, I hit ctrl + s / close and re-open IDE, and then reload my local page for CS50 finance, I seem to experience a very weird issue of randomly changing column order. This happens without me ...
idol2k's user avatar
  • 5
0 votes
1 answer
84 views

PSet 7: Issues with flask table output - hint needed

I am trying to produce table headings using loop in flash but I get new lines after each: {% extends "layout.html" %} {% block title %} Portfolio overview {% endblock %} {% block main %} {% ...
idol2k's user avatar
  • 5
0 votes
1 answer
426 views

For register in pset 7 where I am doing wrong?

Here is my code for register user in database but it is not working, What is my mistake @app.route("/register", methods=["GET","POST"]) def register(): if request.form["username"] == "" or request....
Ahmed Raza's user avatar
0 votes
2 answers
64 views

PS7: Please give me a hint on flask loop usage

Despite reading documentation I cannot figure out why my loop is not functioning properly and is only dynamic for stock symbol? Am I meant to be using multiple nested loops passing all prices, holding ...
idol2k's user avatar
  • 5
0 votes
1 answer
499 views

Pset 7 Variable in SQL statement

I am implementing the subtraction from the user's cash and I can't figure out a way to insert variables into my sql statement. The variables are numbers here. Here is my code: if user_cash > ...
nkom's user avatar
  • 5
0 votes
1 answer
99 views

pset8, import. Only even row numbers from US.txt are being written to db

I managed to import file from US.txt to places table and all seems ok, except that only rows from even numbers in file are being imported. Instead of 40975 rows I have 20487. I tried with while loop(...
Grzegorz Milanowski's user avatar
1 vote
1 answer
74 views

C$50 Finance Pset7 - Buy.php not INSERTing shares correctly

My code for Buy.php. For some reason whenever I fill out both fields of shares and symbol correctly I get the apologize error that the data wasn't inserted into the table correctly. (I don't think I ...
Simonnnn's user avatar
0 votes
2 answers
114 views

PSET7 SQL Query Not Working in buy.php

This is my code for buy.php. I think the issue is with my SQL line, which is "INSERT INTO Stocks (user_id, symbol, shares) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE shares = ?", $_SESSION["id"], ...
DSmith's user avatar
  • 45
0 votes
1 answer
360 views

How to make search.php return results that are more relevant

For pset8 in search.php, I cannot get relevant results to show up. I am using match () against () and I really want to only use this. The problem is, for example, when I type in Cincinnati, I get ...
Sam's user avatar
  • 113
0 votes
1 answer
48 views

Printing from SQL in PHP

I am trying to print text I have placed into a MySql database. I have been able to insert into the database, but I don't know what to put to take out the value/text <?php require("../includes/...
S. B. 's user avatar
0 votes
1 answer
36 views

help me understand GROUP BY in update.php

In update.php we have this query: "SELECT * FROM places WHERE (? <= latitude AND latitude <= ?) AND (? <= longitude AND longitude <= ?) GROUP BY country_code, ...
Lex's user avatar
  • 55
0 votes
1 answer
252 views

register.php pset7

I do not understand why the following code do not work as it should. $result= query("SELECT * FROM users WHERE username = ?", $_POST["username"]); if($result === true) { apologize("Username ...
James C's user avatar
0 votes
1 answer
135 views

Final Project: Trying to access phpmyadmin through CS50 ID (similar to Pset7) but find "This Webpage is Not Available"

I am trying to use SQL in more or less the exact same way as we did in pset7, but whenever I try and access phpmyadmin it tells me the web page is not available. I already checked my chmods, apache, ...
S. Dunn's user avatar
0 votes
1 answer
42 views

LIKE vs equal sign - basic question

I know I can use wildcards such as % with sql's LIKE. Besides this, are there any advantages of LIKE over a simple equal sign? So, has this: SELECT * FROM places WHERE MATCH (postal_code, place_name,...
Lex's user avatar
  • 55
0 votes
1 answer
923 views

Pset8 search.php (still) not working

I can't get sql's "match against" to work. I thought I understood how to do this, except when I actually used sql's match (...) against (...) syntax, I got an error. This error doesn't say anything, ...
David's user avatar
  • 107
0 votes
1 answer
167 views

What does VALUES(shares) refer to in the ON DUPLICATE KEY UPDATE clause?

This is the working snippet: query("INSERT INTO portfolio (id, symbol, shares) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE shares = shares + VALUES(shares)", $_SESSION['id'], $_POST["...
Lex's user avatar
  • 55
1 vote
2 answers
178 views

How do I use SQL transactions?

How do I use SQL transaction with the query function provided by CS50 staff? I tried: query("BEGIN TRANSACTION"); and even: query("START TRANSACTION"); but these didn't work.
Mirko Salaris's user avatar
0 votes
1 answer
292 views

What is wrong with this SQL command?

query("INSERT INTO stocks (id, symbol, shares) VALUES($_SESSION["id"], $_POST["symbol"], $_POST["number"]) ON DUPLICATE KEY UPDATE shares = shares + VALUES(shares)"); I am getting this error Parse ...
Muneeb Hussain's user avatar
0 votes
2 answers
189 views

pset7: query problem

When I try these with query function it is giving me an error: query("SELECT * FROM users WHERE username LIKE %?%", $_POST['username']); query("SELECT * FROM users WHERE username LIKE '%?%'", $_POST['...
Hussain Noor Mohamed's user avatar
0 votes
3 answers
1k views

Finance: Buy/Sell does not insert into MySQL history table

On pset7 and struggling with the history part. When I buy or sell a stock, it's reflected in the portfolio and the cash available is also updated. However, it does not seem to be affecting the ...
Yami Medina's user avatar
0 votes
1 answer
75 views

SQL Order results by score, desc

What SQL query do I have to run to get all of the rows from a table, ordered from highest score to lowest score? I tried a few different queries, none worked. Thanks, David
i_am_david's user avatar
  • 1,211
1 vote
2 answers
98 views

How is Week 9 SQL Atomocity solved?

David said: So in problem set seven, we give you this one line of code, which long story short, solves this problem in MySQL. This very long instruction that doesn't even fit onto one line on ...
RexYuan's user avatar
  • 309
0 votes
1 answer
211 views

pset7 unknown column in where clause

This throws an error saying YHOO is an unknown column...I thought 'symbol' was the column name in this query? $id = 6; $symbol = "YHOO"; $shares_query = query("SELECT shares FROM portfolio WHERE id = ...
SeanIvins's user avatar
2 votes
1 answer
288 views

Problem Set 7 (fighting of SQL injection attack)

Halfway the PS-text it says that using the "query'-function will also ensure "that any such placeholders' values are properly escaped so that your code is not vulnerable to SQL injection attacks.", ...
Gerard de Vries's user avatar
4 votes
2 answers
2k views

How to use current timestamp or now()

In CS50 pset 7, there is a part where you have to use SQL to insert the date and time of a transaction into a table. According to the web, there is a function to do that called CURRENT_TIMESTAMP or ...
user1298's user avatar

1 2
3