+6 votes
by (100 points)

I have problem with query, anybody see something bad?

INSERT INTO messages (subject, from, recipient, text, time)
VALUES
('Welcome in King of the States!','The Game','$username','Hello $username, THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')

Error from sql:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, recipient, text, time) VALUES ('Welcome in King of the States!','The Gam' at line 1

11 Answers

+19 votes
by (100 points)

from is a mysql reserved word. try placing from in backtick

Like below:

`from`
+16 votes
by (100 points)

try to do:

INSERT INTO messages (`subject`, `from`, `recipient`, `text`, `time`)
VALUES
('Welcome in King of the States!','The Game','$username','Hello $username, THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')
+12 votes
by (100 points)

From is the reserve keyword in the mysql so use the below query:

INSERT INTO `messages` (`subject`, `from`, `recipient`, `text`, `time`)
VALUES
('Welcome in King of the States!',
 'The Game','$username',
'Hello $username, 
THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')
+7 votes
by (100 points)
"INSERT INTO messages SET subject='Welcome in King of the States!',from='The Game',recipient='".$username."',text='Hello.$username', time=''";
+1 vote
by (100 points)

Instruction:

from is a keyword in mysql. So you can not use directly in query like this. You need to parse it every time and for that use backtick

use it like from

0 votes
by (100 points)

-g starts becoming useful once you use debuggers such as gdb and lldb. When you attach to a running program and advancing one line at a time printing/altering the state as it changes.

0 votes
by (100 points)

In my knowledge, when I write cin >> a command, program will wait user enter some characters until encounter newline character \n. That characters will be put into stdin.

It is slightly more complicated. C++ program interacts only with standard input stream. How characters ends in it, and how user can provide them to the program depends on OS (or maybe runtime library). Most OS do line buffering which has the behavior you described, but from the program point of view, it is fed a continuous stream of characters.

After that, cin will take fist character and put it into a variable.

It depends on type of a , but I suppose you meant that it has the char type. In this case it performs a formatted input : it discards all whitespace characters (space, tab, newline, vertical tab...) until it either encounters non-space or hits end of stream. You do not see newline printed, because operator>> skips it and waits for non-space character to appear in stream.

0 votes
by (100 points)
0 votes
by (100 points)

I will warn you that regex should not be used for HTML , because it is not a regular language. Instead, use a DOM manipulator like DOMDocument . However, I will still answer your question.

The problem is with (.*) being "greedy" not "lazy" . Regular expressions attempt to match strings, meaning they will always match as much as they can. In this case .* will match 0+ characters. This will go all the way to the end of the string and then start "backtracking" until it finds the next part of your expression (<h2|<div) . If we make this capture group lazy ( (.*?) ), then it will match 0+ characters until it finds the next part of your expression. This means it won't go to the end and backtrack.

I also made some modifications to the overall expression:

<h2>(.*?)</h2>(.*?)(?=<\w+>)

First I made both of our capture groups lazy, for the above reasons. Then I used a "lookahead" so that your last tag isn't unnecessarily matched. Finally, I used <\w+> instead of <h2|<div . This will be more flexible ( \w matches [a-zA-Z0-9_] ).

0 votes
by (100 points)

This is probably not the whole answer, but you're increasing edgeCount twice

heap[++edgeCount] = e;
edgeCount++;

Related questions

+11 votes
8 answers
+7 votes
12 answers
+9 votes
12 answers
asked Jan 19 by coder guy (100 points)
+10 votes
10 answers
...