« first day (544 days earlier)      last day (4395 days later) » 

7:00 PM
oh what do I do now?
 
I'm writing real quick from scratch
It'll be ready in about 10 :)
 
thank u :)
 
evening fellow programmers in our sucky language ;)
@CharlesSprayberry tnx for the suggestion. Will add it
 
Hi, how goes the rep whoring?
 
Yo 'sup!
 
7:13 PM
jo @Chris
 
@DineshVenkata Whew, that was nice
 
thank u
:)
 
Again, haven't done any kind of testing
but that's the principle
 
ah
u have used PDO
 
You don't?
It's enabled by default on PHP 5.1.0+
 
7:20 PM
as in it was only this morning that I came to know
 
I'm using PDO here, because it's more robust and secure than MySQLi, I urge you to learn it and use it instead of MySQLi
 
that mysql has been depreceated
and mysqli or PDO
have to be used
here on
 
mysqli is similar in syntax to mysql
PDO offers a different syntax, a more OOP approach to database managing, and not to mention it works on many kinds of databases, not just MySQL
 
yea that is the reason I was prefered it
since I'm ocmfortable with PDO
 
You'll learn that the syntax is not entirely different
 
7:22 PM
oh great then
 
I've commented the code for you for easy reading
If you've programmed for Android, I assume you're familiar with Exceptions?
@DineshVenkata
 
UTF-8? PAH! From now on, all my PHP scripts will be encoded in EBCDIC. And all my databases will be encoded in an entirely different version of EBCDIC!
 
yes
@truth this also doesnt display the question
 
Let me set up a database and test it myself :)
Heh, silly me
Add this
<?php
echo "<h1>{$question["question"]};</h1>"
?>
Right under the form element
 
7:30 PM
just saw it so removed the line
 
Well, I'm seeing the problem...
It's fetching the question fine, but for some reason it won't display it properly
 
yea
that is problem
 
It's probably something very stupid I'm missing
 
when I'm using the coulmn name it is giving me the undefined index
 
This is a very peculiar problem
 
7:36 PM
so should I use index
instead of column name?
 
No
I'll post it as a question on StackOverflow, see what I can dig up
When getting from a database, it's usually best to use actual names, as in larger queries indices will confuse you
 
what is going wrong the code seems to be perfect
 
Let's see what SO has to say about it :)
 
Oh, see?
Told you it was something stupid that I missed...
PDO returns the result set in the form of an array
$result[ROW_NUMBER]["column_name"] = "whatever"
We forgot to use the ROW_NUMBER, which is 0 (as it is the only row!)
 
7:41 PM
oh
this should be used at $question right?
 
alright
go it to work
<?php
error_reporting(E_ALL);

/*
 * Assuming data structure:
 *
 * mathbro
 * -------
 * id | question | answer1 | answer2 | answer3 | answer4 | is_right
 * ----------------------------------------------------------------
 *
 */
/**
 * @param PDO     $conn
 * @param integer $question_id
 * @param integer $selected_answer
 *
 * @return bool
 */
function check_answer(PDO $conn, $question_id, $selected_answer) {
    //I'm doing it this way to not complicate things! Normally use prepared statements!
Make sure you change the info as needed.
(your database name and credentials)
 
works but doesn't display the options
we should use row number there also right
?
 
It does display for me
Check out the large comment at the top! it assumes the column names are answer1 answer2 answer3 and answer4
If that's not the case, you need to change it at the bottom of the code, where the display occurs
 
yea got it
 
<?php
error_reporting(E_ALL);

/*
 * Assuming data structure:
 *
 * mathbro
 * -------
 * id | question | answer1 | answer2 | answer3 | answer4 | is_right
 * ----------------------------------------------------------------
 *
 */
/**
 * @param PDO     $conn
 * @param integer $question_id
 * @param integer $selected_answer
 *
 * @return bool
 */
function check_answer(PDO $conn, $question_id, $selected_answer) {
    //I'm doing it this way to not complicate things! Normally use prepared statements!
Corrected little debug problem at the <h1> print
 
7:49 PM
but this doesn't display the second question
I have two questions
 
It does for me
I've tested for that
Does it display an error message?
Incorrect! Try again!
 
when I hit the correct answer
I dont get the next question
 
What do you get than?
The original question? No question at all?
@DineshVenkata
 
I get the number that is I'm assuming the first field with no text
 
@DineshVenkata You get the number 2?
 
7:53 PM
yes
 
And that's all you're seeing?
@DineshVenkata 2?
 
yes
@Truth
 
@DineshVenkata Please go to view source, copy everything there, and paste here as code
To paste anything as code, paste it here and press CTRL+K
 
user1385191
don't forget to highlight said code first
 
<html>
<head>
<title></title>

</head>
<body>



<form action="math.php" method="POST">

<h1>2 (1: </h1>

<label><input type="radio" name="ans" value="1"></label>

<label><input type="radio" name="ans" value="2"></label>
<label><input type="radio" name="ans" value="3"></label>
<label><input type="radio" name="ans" value="4"></label>

<input name="current_question" type="hidden" value="2">

<button type="submit">Next</button>
</form>
</body>
</html>
 
7:57 PM
@MattMcDonald No need to highlight code
@DineshVenkata This is what I got when I reached my last question. Are you sure there's a question with ID of 2?
 
sorry nope
the value was 4
 
:)
This is probably the time I should point this out
This script is imperfect, in fact, it's far from perfect
it's correct but not ROBUST, it will only run when it gets what it expects, and will crash awkwardly if it doesn't.
 
yea and u know what if we change the option after hiting the wrong one nothing happens
 
To make a robust program, one needs deeper understanding of the language and the protocol, as well as error handling in PHP. I've kept it this way to not overcomplicate it for you
 
thank u
but how we debug in php
?
 
8:02 PM
Like you debug in any other languages
There are functions to do it for you
var_dump() can help you view the content of variables, to check if they're what you expect
I assume you're familiar with Exceptions already
 
yea
absolutely
 
You just need to expect everything, What if the user entered the wrong question? What if he used some sort of hack to change the answers on your site?
In that case, the $_POST variable will not be what you expect
 
For instance, in the current configuration, someone can easily jump to question 9001 by changing the hidden input
it's hidden in the way that it's not displayed, but a web developer can easily see and change it
 
yea so how do we make the code robust ?
 
8:05 PM
Well, this means anticipating everything
Nothing the user does can be trusted, and EVERYTHING must pass through validation.
The $_POSTed answer must go through validation to make sure it's a number between 1-4
Don't use hidden inputs, we generally use SESSIONS
Use prepared statements when using any kind of information the user provided to prevent MySQL Injection
 
are there any books that u suggest or should i stick to the manuals?
 
The manuals are great
They're filled with useful information
not only the manual itself, but usually the comments associated with that manual entry have ultra useful information
As for books
I usually suggest this one for anyone who asks
 
@Truth as long as you use PDO with ATTR_EMULATE_PREPARES off (which is not default)
4
 
Oh gosh @Truth is still at it.
 
oh great thank u
 
8:09 PM
@ircmaxell Refresh my memory? I don't think I've ever used ATTR_EMULATE_PREPARES
 
@truth
 
@DineshVenkata No problem :)
 
Damn I was reading a PDO tutorial with not that many errors and then: phpro.org/tutorials/Introduction-to-PHP-PDO.html#13
 
@Truth $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false)
 
BAM! downvote
 
8:10 PM
or use MySQLi
 
I suck at regexes .. So, can anyone guide me in direction of how to get everything AFTER a certain word?
 
I was having hard time explaining SQLi so.. i.minus.com/iUUa662xVdbNk.png
 
@Chris /word(.+)/ ?
@ircmaxell Why would you use that? What's the benefit? (I've personally never seen it before)
 
It's that simple? f me.
 
8:12 PM
@Truth I told you 5 minutes ago. So you HAVE seen it before :P
 
@RepWhoringPeeHaa BAZINGA!
 
#word(.*?)#is if you are extracting from some multiline text...
 
@webarto Why would you go with lazy matching? He wants everything after word
 
habit :)
 
Also it's one line.
I'm gonna preg_match this joint up yo'!
(talking PHP in a gangsta way just sounds so cool)
 
8:15 PM
PHP can't be cool even if you talk like that because it sucks
 
@Chris It does although I wonder whether it works 'on the street' too :)
 
@Chris This is why us programmers don't get laid very often...
 
Yes it can, you just gotta speak to people who know nothing of PHP.
 
@Truth Speak for yourself.
 
@Truth it prevents injection in all cases (without it, there are edge cases where even pdo prepared statements can be injected into with mysql)
 
8:17 PM
My programming lingo gets me all the ladies
 
@ircmaxell I see, that's useful. In that case, why isn't it false by default?
Or is it used by other Database drivers?
 
@Truth because core devs decided it shouldn't be
 
I suspect it's false by default to retain BC with versions of mysql that didn't implement prepared statements
I know it's true by default for Postgres
 
code review pls... ideone.com/0rzYg
 
Why not use datetime objects? Surely that'd be easier!
And what about daylight savings?
 
8:21 PM
that can be ignored now, but will have to implement that, not so important now.
I got lost in forest of datetime functions...
MySQL has this function, but I can't find it in PHP manual...
 
@webarto Not datatime functions, DateTime objects
 
There is only one DateTime class :-)
 
Remember it's PHP. There's a function for (almost) everything ;)
 
Ok, I now have to split 18:00-03:00 interval into [0 => 6, 1 => 3] (hours until midnight, and after), any advices :)
hah, yeah, out there, somewhere :)
 
8:29 PM
For some reason, my code returns true and false at the same time and I can't figure out why.
I gotta drink less
 
what's that 0.5 :)
there can be only one return value AFAIK
 
I know, but then why does if(thing == true){ echo'yay'; }else{ echo'boo'; } return both for me?
 
echo $thing == true? 'yay': 'boo';
probably thing is true, and your condition is somehow if then, without else, so both of them get echoed...
 
I do use ifelse
so it most likely is there
f me, elseif() not ifelse ... I really have to drink less.
 
or you run PHP Schrödinger's build :)
 
8:38 PM
var_dump saved my ass, woo!
It ran the code twice and the second result turned false, hence it returned both results.
 
awsm dawg
 
I'm trolling on ##php: $date = (new ReflectionClass('datetime'))->newInstance();
 
noice
 
8:58 PM
code review pls http://ideone.com/FR3x3
result is as expected, but it's too hackish
 
have a long drive to a client tomorrow :( later all
 
l8r
 
9:40 PM
cu
 
Hello everyone. One question. Can i define php variable inside "if" statement? For example: if($get=mysql_query($numbers)) {echo mysql_num_rows($get);} thanks
 
try :)
 
thank you :p
 
@ircmaxell can you elaborate or link to such cases?
 
9:58 PM
hello
is this working? :)
 
this is PHP chat room, you can expect something to not work ;)
 
yea, we all hate what we do.
welcome to the club.
 
haha :D
 
Quote from MSDN... "Even parameterized data can be manipulated by a skilled and determined attacker."
 
great answer webrato
 
10:01 PM
I was actually thinking of learning Ruby instead, but then I got lazy so I chose PHP
 
brate ti si jos na neki nacin i moj zemljak :))
 
I also thought about learning Python, but since my host don't support it and I'm too lazy to switch hosts .. I quickly got rid of that idea, too.
 
o zemljak pa što odma' ne rečeš :)
 
inglise keel ainult, palun.
 
@Chris keyword: localhost :)
ok habla ingles naturlich
 
10:03 PM
:D
 
njet.
 
Just stumbled over this DOMDocument cheat:
$xpath = new DOMXPath(@DOMDocument::loadHTML($html));
$src = $xpath->evaluate("string(//img/@src)");
 
congrats on 40k
 
What about me? I mean, I have 20k without the k.
 
merci
 
10:05 PM
(I'm currently in a state where I don't really have a million questions, but am not smart enough to answer questions either .. so, my rep just doesn't change)
 
lol :D
 
I got Unsung Hero badge... that was a sign to give up...
 
oooh @hakre is at 40k?
awesome
 
@Chris nagu nad saavad sind aru
 
@Chris Actually you can already answer most of the questions on SO, but you are smart enough not to do so ;)
 
10:08 PM
@ArtjomKurapov müsteeriumit tuleb lisada.
@NikiC Perhaps. I figure I'll answer questions when I've developed a time travel machine in PHP. Which will most likely be never.
 
yep, im waiting til I get my golden badge too :)
 
@NikiC: I can't watch that video, this type of "talking" gets on my nerves
 
@hakre Yeah, auto-generated ^^
 
@Chris Now you've got 40'k' as well ;)
 
Still nice. I think that voice actually makes those vids better :D
 
10:13 PM
Huh, what
 
40k of 1/1000 points
 
somehow this is close to art: themis.myrayhawk.com/traceroute.php?2
 
nah, just jQuery :)
 
Hello again, if($num=mysql_num_rows($gp)>1){echo $num;} keeps outputting 1, no matter how many rows i have. Echoing "mysql_num_rows($gp)" instead of "$num" works fine. Thanks for the answer :)
edit if(..>0)
 
Write it this way instead:
if (($num = mysql_num_rows($gp)) > 1 ) {echo $num;}
 
10:19 PM
@hakre it works like a charm. Thank you very much :)
 
got task to fix bug, had to rewrite half of the app :/
 
XPath query on a HTML document as a PHP one-liner:
$src = (string) reset(simplexml_import_dom(DOMDocument::loadHTML($html))->xpath("//img/@src"));
 
kewl
 
well, no error checking.
will give a fatal error if $html is empty.
 
what if there were multiple elements?
$src would be array?
 
10:41 PM
So, ubuntu 12 beta out.
Gonna give it a shot.
 
Officially hates Zend & Doctrine...
@Chris what are you running atm?
 
My beloved Win 7
 
I was thinking of installing win8, but dunno if it could be upgraded to retail version once it's out...
 
10:58 PM
i think i need a nap
is there something i could troll about ?
 
troll about cats
you can always troll about cats
@webarto I'm gonna install win8 .. never probably. Perhaps win9 if it has better interface.
 
CAM
excute a stored procedure via PDO issues
 
But by the time win9 comes out I'm pretty sure I have saved enough money for a mac, so screw win.
 
CAM
? I can run it in my mysql client but via PDO i fail
 
"i fail" is not a valid error message , @CAM
=P
 
11:02 PM
mysql syntax error near 'i fail'
 
CAM
It returns an empty array
 
why do you need PDO for stored procedures?
 
CAM
I don't nessasarily
$sql = "CALL st_proc('2012-04-01', '2012-04-03', 26);";
var_dump($DBH->query($sql));
 
I'm off to bed. Later all!
 
emm ... it should return a statement
you need to fetch results you actually get something
 
CAM
11:06 PM
$sql = "CALL st_proc('2012-04-01', '2012-04-03', 26);";
$DBH->query($sql);
$STH->execute();

$rows = $STH->fetchObject();

var_dump($rows);
 
additionally , CALL foobar tells nothing about what it is actually doing
 
CAM
ok
 
also , @CAM , that cannot return an empty array
and your $STH is not an object
you are really bad at this ...
 
CAM
if I run CALL zone_geo_graph('2012-04-01', '2012-04-03', 26); in mysql it return my values
include_once('inc/config.db.php');

$sql = "CALL zone_geo_graph('2012-04-01', '2012-04-03', 26);";
$STH = $DBH->prepare($sql);
$STH->execute();

$rows = $STH->fetch();

var_dump($rows);
 
step one : make an example that actually makes sense
step two : show what is inside the procedure
 
CAM
11:09 PM
@tereško c'mon
ok
 
@CAM you asked for it :)
 
CAM
CREATE PROCEDURE zone_geo_graph(IN df DATE, IN dt DATE, IN zid INT, IN lmt INT)
BEGIN

#Drop Tmp Table
DROP TABLE IF EXISTS zgg;

# create Temp Table
CREATE TABLE `zgg` (
`country_short` varchar(2) NOT NULL DEFAULT '',
`uniques` int(11) NOT NULL,
`date` date NOT NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1;

# While j < i then j++
WHILE df <= dt DO
#OUTPUT
INSERT INTO zgg
SELECT country_short, uniques, `date`
FROM stats_geo
WHERE zone_id = zid AND `date` >= df AND `date` <= dt
GROUP BY country_short
 
also .. $STH = $DBH->query($sql);
 
CAM
@tereško does that make more sense?
 
you really suck at the step one
 
CAM
11:11 PM
$DBH refers to my PDO object
@tereško I stumped ya huh?
 
Hey
 
yeah ... looks like it should give you a result
 
just run effin mysql(i)_query :)
 
CAM
Hmm
PDO
I like PDO
 
PDO doesn't like you
nor does Doctrine likes me
 
CAM
11:14 PM
@webarto thanks of rnothing
 
What're you using doctrine with
 
echo levenshtein('of r', 'for'); # 2
with Zend Framework, some web hosting support app from 2009...
"stopped" working, I never worked with Zend/Doctrine... so that's why I hate it :)
 
@CAM , did you make sure that there were no execution errors ?
 
CAM
uh... yea
 
also , i have usually been selecting the temporary table AFTER the procedure has been executed
in a separate query
 
11:20 PM
I would still go with mysql_query to be sure...
 
CAM
But it works in mysql
But DB conns are PDO
ok make a new one and down grade great idea
 
i can take a second looks at it tomorrow
now its time for nap
@webarto , why would ANYONE what to use that outdated crap ?
 
CAM
@tereško tucker you out, way to help
 
huh ?
 
@tereško because of a reason :) to eliminate it is a PDO issue... duh
 
CAM
11:23 PM
you are all tuckered out form thinking about my big boy problems?
 
no, it is 3am an i have to wake up in 4 hours
=P
 
CAM
its not PDO ; its my implementation
wuss
 
stupid
 
@tereško what is your timezone?
+2, so it's 2:26
@CAM do you really need tmp table for this?
 
CAM
YA
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: Syntax error or access violation:
 
11:35 PM
have you tried running separate queries like tereško suggested?
 
CAM
HAHAHAHHAHAHAH I ran the stored proc on my Dev box
not the Prod server
HAHAHAHHAHAHA
 
:facepalm:
 
I use that "old outdated crap" because i need to debug production :(
and phpbuglost doesnt support anything smarter
 
how does that help you :S
ah
 
and i dont want to edit it myself
 
CAM
11:37 PM
yea I'm just dumb
i run crazy is in dev
so i don't crash prod
 
well its not that it crashes
its to find slow queries
i can switch back to other adapters once i'm done
still...
 
CAM
yea
i mok
 
ran into some of old code, pron is all about sharing, so...

    set_time_limit(0);

    $html = file_get_contents('http://www.redtube.com/98250');

    preg_match('#mp4_url=([^&]+)#is', $html, $matches);
    $url = urldecode($matches[1]);

    preg_match('#([0-9]+)\.mp4#is', $url, $matches);
    $file = $matches[0];

    $start = microtime(true);
    file_put_contents($file, file_get_contents($url));
    echo round(microtime(true) - $start);
TGIF BTW
 

« first day (544 days earlier)      last day (4395 days later) »