« first day (662 days earlier)      last day (4272 days later) » 

6:00 AM
$sql = $db->prepare("SELECT username from students where username=?");
$sql->execute(array($user_check));
crosses fingers
 
you should capitalize the FROM and WHERE, but otherwise it looks good.
 
awesome!
 
why are you selecting the username from students when you already know the username?
 
Its the session check
 
?
 
6:03 AM
$user_check=$_SESSION['login_user'];

$sql = $db->prepare("SELECT username FROM students WHERE username=?");
$sql->execute(array($user_check));
 
you should store the user ID in the session, not the actual username. you're just checking to make sure that the username exists in the database?
 
does the USING keyword even work in mysql?
 
If I get data from one server, how can I change that server to another and using ssh publick key?
 
$row=mysql_fetch_array($sql);
$login_session=$row['username'];

using PDO?
 
6:08 AM
are you asking how to do that using PDO?
 
Yes
 
@Nile Me? No, not pdo.
 
@DanielsPitkevičs, no, sorry.
@AlexCastro, use $query->fetch();
or ->fetchAll() depending on the use
 
Hello! I have got an idea for a wordpress plugin. Am thinking of putting it on github. The idea is to 'use stackoverflow markdown with wordpress'. Should I?
P.S. I am very much interested in developing that. But, would also like to know if it exists.
 
@goldenparrot What do You mean by stackoverflow markdown?
 
6:10 AM
the post formatting things
_ ** ` etc.
 
@Nile
$sql = $db->prepare("SELECT username FROM students WHERE username=?");
$sql->execute(array($user_check));
$row = $sql->fetch(PDO::FETCH_ASSOC)
Look good?
 
$row = $statement->fetch(PDO_FETCH_ASSOC);
$login_session = $row['username'];
 
tell me what you're trying to do. are you trying to make sure that atleast 1 row is outputted?
 
I just need to set this variable: $login_session = $row['username'];
I think @cHao got it
 
@AlexCastro alright
 
6:14 AM
how to rotate a video 180 degree in ffmpeg
 
...is a perfect title for a subject not related to php
 
why isnt that relevant?
 
oops. PDO::FETCH_ASSOC, not PDO_FETCH_ASSOC
@AlexCastro looks ok to me
 
@cHao What looks okay? Want to make sure we're on the same page
 
any one help : how to rotate a video 180 degree in ffmpeg
 
6:18 AM
@goldenparrot Go on with that, I suppose there could be such thing, but not many, so it could be quite useful.
 
@AlexCastro this
 
Ahk thanks
 
though personally, i'd call the statement something besides $sql. that variable name i typically reserve for strings containing SQL
i usually use $stmt, or a name appropriate to what the query does
 
Hmm, okay
How should I re-write mysql_real_escape_string
 
6:22 AM
ready for this?
drum roll
 
you don't. that's the beauty of prepared statements...they escape your data for you.
 
:D
 
whuuuut
awesome
 
thats as long as you remember to use either "?" or ":variable", never do a $variable unless it's for the column names and required in that situation.
 
so how would I put an item gotten from POST?
 
6:24 AM
yeah...the auto escaping thing only works if you keep to the goals of prepared statements: to keep your data and your sql separate
 
does anyone else get annoyed by the fact that the first conditional statement in a query must start with WHERE, but then all subsequent ones must start with AND?
 
@AlexCastro you'd put it in the array you pass to $stmt->execute()
 
ah okay
Should I still do stripslashes?
 
and, of course, have an appropriate placeholder in the query string :)
@AlexCastro only if you have magic quotes enabled for some braindead reason
 
I don't know what that is so I probably didn't do it.
 
6:26 AM
check to see then
 
@AlexCastro thats the question mark
 
so if I do VALUES(?, ?) then I need stripslashes?
 
@AlexCastro run this real quick: die(((get_magic_quotes_gpc()) ? "en" ? "dis") . "abled");
 
My pages are all broken
Cause I'm half way through converting
 
it doesn't matter, just put it at the top of a page and execute the page
 
6:28 AM
@AlexCastro sorry, thought you were saying you didnt know what the placeholder is :P disregard my comment
 
@AlexCastro you don't need it unless you have magic quotes on. if you don't, then stripslashes will mangle your data
 
Will it have any problems with md5()?
 
which isn't terrible for text, cause there are rarely backslashes in it. but for raw data...could cause problems
 
md5? for what would you be using md5 for other than creating random unique strings?
 
A password
 
6:30 AM
Oh, I thought we use bcrypt for that
 
Is using bcrypt complicated? I've read about it but don't need passwords that secure for this project.
 
@AlexCastro But yeah... look into bcrypt. md5 is for checksums. back to your question. will md5 have problems with what?
I use the class in the first answer on this post:
182
Q: How do you use bcrypt for hashing passwords in PHP?

Vilx-Every now and then I hear the advice "Use bcrypt for storing passwords in PHP, bcrypt rulllez!!!11" OK, but what is this bcrypt? PHP doesn't offer any such functions, wikipedia babbles about a file-encryption utility and Googling just reveals a few implementations of blowfish in different langua...

Super simple class to use.
 
Haha I'm reading that now
 
whats wrong with just using hash('sha256','string')?
 
either way, hashing will only have problems if the data you're hashing is notthe data you're expecting to hash
@AndyPerlitch you mean, besides the fact that hash isn't listed anywhere in the php docs? :)
 
ooo. i stand corrected. spiffy.
where doyou specify the salt, though?
 
why not just concat it to the string?
before hashing?
 
If I want to pass many variables do I just put a comma like
$sql->execute(array($username, $password));
 
@AndyPerlitch hash is used for checksums also
@AlexCastro yeah
 
6:38 AM
@AndyPerlitch could do that, i guess
 
Cool
How would I do this in PDO?
if(mysql_num_rows($query) == 1)
 
@Nile ok so what do checksums have to do with salts though?
or do they
 
if ($stmt->rowCount() == 1)
 
Thanks Chao!
 
no?
does that work?
I thought rowCount doesnt work with mysql
 
6:40 AM
ooo...yeah,you're right :P
hold on, then
 
@AlexCastro, you need to use the SQL COUNT(*) function
7
Q: Count with PDO

JamesThere are many conflicting statements around, what is the best way to row count using PDO in PHP with MySQL? Before using PDO I just simply used mysql_num_rows. FetchAll is something I won't want as I may sometimes be dealing with large datasets, so not good for my use. Any suggestions?

 
or, if ($stmt->fetch() && !$stmt->fetch()) :)
 
im just gonna go ahead and throw a wrench in this lesson and say mysqli is better than pdo
 
it's wasteful, but it'll fail unless it manages to fetch one row and not two
 
@AndyPerlitch nooo
 
6:43 AM
Wait so what am I supposed to do, haha
 
@AndyPerlitch lol....stop that!
 
hahah sorry
couldnt help it
 
you can chose either of the solutions @AlexCastro
 
I'm sticking with PDO
 
@AlexCastro will there ever be more than one row?
as in, are you just checking for 0 or 1?
or 2, 3, ...?
 
6:44 AM
It's just looking for a username
 
@AlexCastro for 0 or 1 row, you don't need a row count...just fetch a row. it'll return a (non-empty, and thus truthy) array if there's one to get, and false if there isn't
 
Just finished the latest episode of breaking bad. With all the pausing and coming to this chat, it took like 2 hours
 
@Nile DUDE me too
crazy
 
haha
 
fkn skyler
 
6:46 AM
@AndyPerlitch, do you know about codepen.io?
 
nope
 
well its a pretty cool website... check it out:
 
wow that does look pretty sweet
 
$sql = $db->prepare("SELECT username,password FROM students WHERE username=? and password=?");
$sql->execute(array($username, $password));

if ($sql->rowCount() == 1){
session_register("username");
$_SESSION['login_user']=$username;
header("location: index.php");
}
So that's wrong?
 
yeah
 
6:48 AM
@Nile bahahaha tell me you did that
 
no, i wish
 
if you ever really need a count, $allRows = $stmt->fetchAll(PDO::FETCH_ASSOC); and check count($allRows) :)
 
@AndyPerlitch hardly know how to use canvas myself
 
yeah...apparently rowCount doesn't work with select statements; just ones that modify data
 
okay
 
6:49 AM
what's with the session_register?
 
Online guides...
 
i thought that was deprecated
 
@Nile same, just one of those things to get around to
 
it is deprecated. don't use it
 
along with backbone, express.js, zoomoos, et al...
 
6:51 AM
@AndyPerlitch I've used it once to make a parabola grapher... it can't be that much different than AS 3, can it? lol
 
just say $_SESSION['login_user'] = $username;
no need to register $username at all, really
 
Oh okay so I'll remove that line
 
@AlexCastro of course it's still probably better to assign the user id
 
my experience with AS3 is extremely limited (started web dev around the time flash started being phased out )
 
just use $_SESSION['login_user'] instead
 
6:53 AM
They can't have duplicate usernames, so doesn't it really not make a difference?
 
@AndyPerlitch have you ever played a game called "Alien Force" by Robert Epps back in the day?
 
@Nile nope. you ever heard of lugaru?
 
no
@AndyPerlitch anyways, I remade Alien Force into AS3 being bored one day: eg.jfein.net/space
 
@Nile pastebin.com/BrQjtKXW look good?
 
@AlexCastro as far as I can tell.
 
6:55 AM
@Nile haha epic
 
Thanks @Nile
 
@AlexCastro might want to capitalize the AND
@AndyPerlitch source code at eg.jfein.net/space/space.as just in case you want to admire my second as3 game... it's not that good, but I hardly know as3 so... :/
 
This pastebin.com/dz3u6rps returns "Parse error: syntax error, unexpected T_VARIABLE"
on the last line
 
looks pretty java-ee
sweet
im still checkin out codepen...its crazy what ppl are doing with css3 these days
 
@AlexCastro you're missing a semicolon on the line before
 
6:58 AM
Gah, thanks
 
@AndyPerlitch yeah, css3 animations... another one of those things I'll learn eventually.
 
What have you gotten me into, haha?
SQLSTATE[HY000] [2019] Can't initialize character set UTF-8 (path: /usr/share/mysql/charsets/)
 
try utf8 instead of UTF-8
 
I don't set utf8 anywhere
 
in your new PDO(...)
 
6:59 AM
or UTF-8
 
@AlexCastro show me where you initialize connection to the database
 
@Nile argh so much to learn. its awesome and frustrating at the same time.
 
@AndyPerlitch yeah, haha
 
my projects just get so deprecated so fast it seems
i look back at projects i was doing 6 months ago and im just like holy god
i was still doing it THAT WAY??
 
Got it to work, thanks @Nile.
 
7:02 AM
I looked at an old class I have and I found:
class Hello {
function __construct($blah){

}
function Hello($blah){ $this->__construct($blah); }
}
 
Of course thats so old and deprecated.
I would know this
How could you still be using that ugly code?
 
are you being sarcastic?
 
hahaha
I have no clue
 
@Nile blahahaha
 
oh php 4
0
Q: marquee is not working properly in php loop

user1583775I am trying to run a marquee in php loop through this code but marquee is not working properly.here is my code <?php foreach($module_settings['DYNAMIC'] as $sponsor):?> <?php if($sponsor['status'] == 'active'):?> <?php if( ! empty(...

 
7:05 AM
"Great, we're done with php4! OOP? Yea i guess we could throw that in there..."
 
except php4 didn't have __construct, iirc
 
<marquee>!?!?!
 
that came with 5
oh, wait...
 
@cHao yeah, thats why you had to do function Classname
 
yeah...so both ways construct the object...k, i get it
 
7:06 AM
man and i havent even begun to mess with namespaces in 5
 
but lol
php4 died ages ago
 
in webdev, ages is like, 2 yrs
 
eons, then
 
lmao
 
well there were still people who used it so you needed to support it.
 
7:07 AM
i didn't need to support it :)
 
[tag: IE-horror]
lol
 
@Nile rewrite?
$sql = $db->prepare("SELECT * FROM courses");

while($row = mysql_fetch_array($result))
 
i ran the servers...so they had php 5 on them, whether the boss liked it or not :)
 
second line, how would I rewrite it
 
$sql->fetch()
 
7:09 AM
Okay
 
but you need to execute that prepare statement
oh!!!!
 
@Nile and @cHao did you guys go to school for programming before getting into webdev?
 
no, dont.
 
nope. entirely self taught
 
@cHao when did you start?
 
7:10 AM
@AlexCastro, it doesn't require a prepare since it has no variables. just use query
self-taught also
 
2000 or so? i was programming before that, but that was my first contact with php
 
So @Nile I do or don't need the prepare?
 
$sql = $db->query("SELECT * FROM courses");
while($row = $sql->fetch()) {
 
ok, i need to get to bed
 
7:12 AM
Thanks Nile
 
i'm already gonna be useless in the morning...lol
 
same, im out too
 
oh wait!
 
lol you're killing me smalls
 
(not you guys, @AlexCastro wait!)
 
7:12 AM
:)
noght
night too
 
haha ok peace out @Nile and @cHao
 
Night @cHao and thanks for the help
 
you too @AlexCastro
 
np :)
 
see ya
 
7:13 AM
good luck
 
actually @AlexCastro try that out I think it should work
 
Night @AndyPerlitch, thanks
Will do
Perfect
Thanks
 
okay, I'm gonna go to now @AlexCastro. 1 minute to ask last minute questions
 
ummm hold on! haha
$sql = "SELECT * FROM students WHERE username = '" . $username . "'";
$result = mysql_query($sql) or die('error');
$row = mysql_fetch_assoc($result);
if(mysql_num_rows($result)) {
$errors .= "<li>Username exists</li>";
}
I can do the first line, but the rest I don't know yet.
 
you know how to do this...
the first two lines you mean?
 
7:18 AM
The second one is the one I'm lost on actually
Would I just fetch
 
the second one is just executing the prepared statement
 
Okay so I can just fetch
 
not for the second line
for the third line you can
here:
 
$sql = $db->prepare("SELECT * FROM students WHERE username = ?");
$sql->execute(array($username));
So far
so good
 
$sql = $db->preapre("SELECT * FROM students WHERE username = ?");
$sql->execute(array($username));
if($sql->fetch()) {
//username exists
}
 
7:20 AM
if($sql->fetch()) is basically checking if it returns something, right?
 
no
> Fetches the next row from a result set
 
Okay so it's saying
if it fetches something
do this
 
yeah, so if there is something to fetch, do this
 
Okay cool
 
But it also deletes the next row from the result set I think
 
7:24 AM
Oh okay
$student_id = mysql_insert_id();
Ah that line
How do I do the equivalent
 
these are real easy google questions
$sql->lastInsertId();
 
Okay thanks
Got a real question now
 
yeah?
 
I have a database built which assigns users to classes
And then assignments are assigned to classes
 
ok
 
7:26 AM
So I'm going to have to have a page for each course
How should I set up that page system?
 
the url should look something like: course?id=5
 
I could set up a class.php?classname=whatever kind of thing
Yes, the real question I have is what is that called?
 
or course/class-name/5
 
I need to be able to do searches and honestly have non clue what it's even called, haha
 
$_GET?
get data
 
7:27 AM
How would GET work from the database?
 
search php get and you'll get lots of things
 
Okay
 
$query = $pdo->prepare("SELECT * FROM `courses` WHERE `id` = ?);
$query->execute(array($_GET['id']));
Then you have courses.* from that course.id
 
So I could build it using links
Like, link classes with a href="site.com/course=5"
 
its how I would do it.
yeah, you could fancy that up with mod-rewrite and make it like:
site.com/learn-php-in-five-second/10
where the middle variable doesn't mean anything, but the /10 = ?id=10
 
7:30 AM
okay okay
 
but that's all after you've got the system going
 
How would I send the variable though?
I mean, lets say I direct a user to the link course=5
 
$_GET['id']
yeah.
 
hey guys
 
How would I tell it it's on 5?
 
7:30 AM
$_GET['course']; //5
 
Hey user155
ah okay cool
Didn't know links worked like that, awesome.
 
anybody here know how can i login to gmail through curl ??i did that but its keep reloading :(
 
@AlexCastro any more last questions
 
0
Q: How to login to gmail through with curl?

user677715Hey, I was trying to login through command line using curl. Following Error is displayed every time "Moved Temporarily" I used the curl command curl -u username:password http://mail.google.com/mail -v How to resolve this ?

Hmm
Checking if a user is in a certain class
 
that's SQL
 
7:32 AM
The enrollments table is like
id student_id course_id
 
SELECT * FROM enrollments WHERE student_id = ? AND course_id = ?
 
So how can I find if that student_id corresponds with the course_id
 
thanks fro this, but that's only for login and see messages via XML... im looking to send SMS from gmail
 
okay
 
@AlexCastro is that what you were looking for?
 
7:33 AM
I think so
 
@AlexCastro any more?
 
Well, what would the if statement for that look like?
For that last SQL statement
 
if($query->fetch()){ //user is in class } else { //user is not in class }
 
You are awesome!
Thanks
 
@AlexCastro lol, thanks. any more?
 
7:35 AM
Hmmmmm
You give me this option I must think of what I need! haha
 
if you don't its fine...
 
haha
Well
If I want to list all the classes a user is in
I'd do a variation of the above
 
well... gosh
you could but you'd only be able to get the class ID
if you wanted to get more information without running 2 queries, you'd need an inner join
 
How would you recommend then?
 
which is definitely not something I'm good at.
 
7:37 AM
I'd just need to list a user's classes
 
Just the class IDs?
 
You're right, I'd need to get the classID and then join that to the class name
 
yea
or run 2 queries
 
Whatever you can do, haha
and I'd use the classID for each to form the link
Things are falling in place..
 
SELECT enrollment.*, courses.*
FROM enrollment INNER JOIN students ON enrollment.course_id = courses.id
WHERE enrollment.user_id = ?
i think that's how you'd do it
 
7:43 AM
missing PDO stuff right?
 
yes, that's the sql
 
okay
 
*enrollment.user_id should be enrollment.student_id
done?
 
uhm
Yes
I hope I see you again and get another chance to bog you down with questions!
haha
 
okay, good night. if you have more questions refer to the manual
you too
 
7:45 AM
Will do, I really appreciate all your help!
 
no problem, bye
 
Have a good night
 

« first day (662 days earlier)      last day (4272 days later) »