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

4:06 AM
aaaarrrrgh
i hate naming stuff
 
@cHao I've done what you said and the array gives me
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
)
1
I don't see how this really helps me, since it's just listing the course ID for each entry
 
let's see the code you have now
 
Do you want to allow users to sign up for multiple courses in the same form btw?
 
Yes, @Nile
That code might actually be what I need
 
okay.
 
4:08 AM
It shows the course_ids selected
Yup, sorry, works perfectly!
It returns the course_ids selected
 
k :)
 
Now I just need to create a loop for enrollments and I'm good
 
yep
 
Something like this? foreach ($arr as $value) {
echo "Value: $value<br />\n";
}
Of course modified, but the loop
 
that should work
 
4:11 AM
yeah
 
Awesome, thanks guys.
 
np :)
 
@AlexCastro Is $arr coming from $_POST?
 
Yeah it's coming from $_POST['class']
It's working fine please dont tell me this is deprecated or something
 
Also, since you're not using a prepare statement, be sure to use mysql_real_escape_string()
 
4:12 AM
nope, its good.
 
Haha great, Paul
Yup @Nile. I'm defining all the variables beforehand with mysql_real_escape_string()
 
or since you aren't using a prepare statement, be sure to switch to PDO or mysqli and use one.
 
you may even want to validate that the ID you're getting from the checkbox actually exists just so you don't get an error
(that'd be embarrassing)
 
hi all,
I have problem in .htaccess file/ url rewrite rules, here is one which don't redirect to the correct page: RewriteRule ^cat-([0-9]+)\.html$ ad_list_cat.php?category_no=$1
 
4:22 AM
@Muhammad, when you visit cat-?.html, what happens?
 
"does not work" is not really a standard error message
 
error 404
 
@Muhammad and what do you see in error log ?
 
+ what happens when you visit ad_list_cat.php?category_no=?
 
Hello, morning..
 
4:25 AM
its ok, the page open on visit ad_list_cat.php?category_no=1
hello Davinder
where can I check the log?
 
depends on your server configuration
 
any help to check the log?
 
it usually would be in /var/log/httpd/error_log
 
So, is it safe to assume that 95% of users cannot alter/manipulate/beam $_SESSION variables? or total 100%?
 
Hey guys, I'm having a weird issue with mysql_real_escape_string()
 
4:27 AM
@AlexCastro, whats the problem?
 
For my radio button list of name="class[]"
 
mysql_real_escape_string($_POST['class'])
seems to be empty
 
Yeah...
It's _string for a reason
 
I do an if empty check, and it turns up empty
 
4:28 AM
You have to do it in your foreach loop
 
@Davinder , if your code is not vulnerable to script injection, then yes , session are as safe as your webserver
 
@Nile Thanks .. reading now..
 
user895378
Readability is wayyyyyyyyy more important than your cutesy one-liner. The longer you write code the more you realize that "clever" is the enemy. Be as explicit as is reasonable at ALL times in your code. — rdlowrey 11 secs ago
 
@Nile so in my foreach ($class as $value) I would treat $value (in the loop) as mysql_real_escape_string($value)?
 
foreach($class as $value) { $value = mysql_real_escape_string($value); }
 
4:30 AM
Yeah, thanks!
 
@teresko I have xampp server, couldn't find the log file.
 
np ;)
 
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." (c) Brian Kernighan — tereško 22 secs ago
3
=P
 
user895378
@tereško Nice.
 
is the rewrite engine on?
 
4:31 AM
@Muhammad , if you cannot find the logs , then there is nothign i can help you with
 
@tereško ok let me check.
 
user895378
lol I couldn't help it -- it's already closed, but I just wanted to share the awesomeness:
 
user895378
-2
Q: Is yii really best framework on planet for high performance php web development

user1481509i saw a list of features in different php frameworks here yii showing almost all important features is codeigniter really lack of features like EDP

 
Posts like this make me loose hope in humanity
why would you have server on desktop OS ?!
 
@tereško Sorry, I thought he may be using it in his local environment..
 
4:39 AM
@te
@tereško here is the log
@tereško 127.0.0.1 - - [08/Aug/2012:09:37:20 +0500] "GET /cat-1.html HTTP/1.1" 404 1186 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11"
127.0.0.1 - - [08/Aug/2012:09:37:20 +0500] "GET /favicon.ico HTTP/1.1" 404 1186 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11"
 
that's access log
 
@tereško yes
 
he wants to see your error_log
 
and the RewriteEngine was not triggered
 
here is error_log: Wed Aug 08 09:37:20 2012] [error] [client 127.0.0.1] script 'C:/XAMPP/xampp/htdocs/cat-1.php' not found or unable to stat
[Wed Aug 08 09:37:20 2012] [error] [client 127.0.0.1] File does not exist: C:/XAMPP/xampp/htdocs/favicon.ico
 
4:42 AM
can you pastebin the .htaccess file ?
 
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]
RewriteRule ^cat-([0-9]+)\.html$ contents/ad_list_cat.php?category_no=$1
 
one rewrite rule is conflicting with the other
 
@Nile how? which one?
 
I'm not too familiar with rewrite rules, try putting the second one before the first one
 
@Muhammad you'll probably want to move the second rule above the first, and add a [L] flag to it so the other rewrite doesn't take effect
actually, no need for the [L]
cause once the first rewrite is done, the second rule won't match
 
4:48 AM
good its ok, without [L]
 
@Muhammad, as an alternative you could also keep the remaining order but change the second rules ".html" to ".php"
 
as it is now, if you go to cat-1.html, the first rule matches and rewrites to cat-1.php
so then the second rule doesn't match
 
YES
 
Hey @Nile, when I do
mysql_query("INSERT INTO enrollments (ID, student_id, course_id) VALUES('', '$whathere?', '$class') ")
I'm not sure what to put into student_id, as the user is being created just one line before, so the ID hasn't been generated for them yet.
 
@Muhammad
> 127.0.0.1 - - [08/Aug/2012:09:37:20 +0500] "GET /cat-1.html HTTP/1.1" 404 1186 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11"
> Wed Aug 08 09:37:20 2012] [error] [client 127.0.0.1] script 'C:/XAMPP/xampp/htdocs/cat-1.php' not found or unable to stat
 
4:50 AM
@AlexCastro is the id field auto_increment?
 
Yes
 
@AlexCastro, you'd have to query the database to figure it out
 
@Muhammad , now look at the two rules :
RewriteRule ^(.*)\.html$ $1.php [nc]
RewriteRule ^cat-([0-9]+)\.html$ contents/ad_list_cat.php?category_no=$1
 
@AlexCastro then don't include it in the insert
 
cHao, the student_id is different
It's a different table
 
4:51 AM
the student id and course id, you include. but the enrollment id, don't even mention it in the query. it'll be filled in automatically
 
@cHao, is there a way to return the row inserted from an INSERT function within the query?
 
That I know
 
@AlexCastro obviously not, cause you're including it
@Nile update doesn't insert rows. that's why it's called "update" and not "insert". :)
 
sorry I meant insert, fixed.
 
@terešk both are working, let me add 3rd line
 
4:53 AM
So, how can I get the last student_id put just after it's inserted on the same page load?
 
@Nile you can't return the whole row, that i know of. but you can get the last auto-inserted id, and use it to get the row after the fact
 
Should I get the one before and add onne?
 
use mysql_insert_id()
(if you have to use mysql_*, that is)
 
yup
 
mysqli_insert_id($link) works the same, iirc
 
4:54 AM
Could you explain a little more exactly what I need to do? Not sure I get that statement.
 
> Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT).
 
On the same page load?
 
on the same connection to the db
 
yeah
 
$whatthe = mysql_insert_id();
mysql_query("INSERT INTO enrollments (ID, student_id, course_id) VALUES('', '$whatthe?', '$class') ");
 
4:55 AM
so yeah, same page load, at the very least
 
@teresko @Nile the 3rd one is also working... thank you so much...
@teresko @Nile Options +FollowSymlinks
RewriteEngine on
RewriteRule ^cat-([0-9]+)\.html$ contents/ad_list_cat.php?category_no=$1
RewriteRule ^sub-cat-([0-9]+)\.html$ contents/ad_list_sub_cat.php?sub_category_no=$1
RewriteRule ^(.*)\.html$ $1.php [nc]
 
$whatthe = mysql_insert_id();
 
and get rid of the ID field in the query
 
How does it know that it's the latest one?
 
every time i see someone linking to http://www.phpframeworks.com , i want to throw things
 
4:56 AM
mysql_* is smart stupid like that
 
hrm
okay
 
every time you see someone mention frameworks at all, you seem to want to throw things :P
 
haha
 
lol thanks
 
@Nile why the ? after $whatthe?
 
4:58 AM
my bad.
 
damn it all. i swore i wouldn't help another w3schools dropout write more mysql_query code.
 
Ah, okay, haha
Hahaha I swear I've steered clear from w3
 
w3 is a friend
w3schools is not
 
@AlexCastro you mean you've picked up their bad habits telepathically? that's rather impressive.
 
w3schools I mean!
I've actually seen a lot of my stuff from some Tizag site I think
 
5:00 AM
ahh tizag...
the last time any of that content was updated was probably around 2003
 
It ranks high on google, haha
 
@Nile which would be about the time mysql_query was still relevant, iirc. :)
 
I used to be a top-poster on their forums
yup.
 
Orrly
So why is w3schools so bad? I mean, don't they have programmers updating their stuff?
 
5:02 AM
@AlexCastro honestly, it would take less than an hour to learn and .33 (repeating of course) seconds to appreciate (referring to PDO)
 
@teresko @Nile now how to refer in my href here its ok but,
 
what ?
 
@teresko @Nile echo "<h3><p><a href='/cat-1.html'>".$info1['category_name']."</a></p></h3>";
 
@AlexCastro , please read w3fools.com
 
echo "<h3><p><a href='/contents/ad_list_cat.php?category_no=$category_no'>".$info1['category_nam‌​e']."</a></p></h3>";
this is my actual line.
 
5:04 AM
@AlexCastro they have people updating stuff. slowly, and half the time it's just as bad after the update as before
 
@Muhammad yeah...?
 
in which I refer to a variable $category_no
 
echo "<h3><p><a href='/cat-{$category_no}.html'>".$info1['category_name']."</a></p></h3>";
 
but in the new one I have to hard code.
 
how do you check whether a site exists or not..
something like a DNS lookup... but to know whether a site is purchasable or not..
`gethostbyname` gives the IP but...
 
5:05 AM
and they seem to always go with code that demonstrates worst practices. presumably because it looks simpler. but it breaks the second someone tries to use it
 
@Nile Greatttttttttttttttttttt
 
@Muhammad you should read up on concatenation
 
ok
 
you go with w3schools crap code, you get stuff like "I'm sorry, "O'Malley" is an invalid name. Please pick a valid name.", or an sql error when you try to actually run the query. And that's if you're lucky, and Little Bobby Tables isn't trying to fill in your form.
bah.
</rant>
 
@cHao :D
 
5:11 AM
@Nile I get this error for some reason Duplicate entry '3-0' for key 'student_id'
 
you have a unique index on (student_id, course_id)?
@ShyamK whois
that'll tell you whether the domain exists and when it expires...as well as who owns it
well, assuming they haven't done a private registration
 
Okay nevermind. It works fine.
 
in which case it'll give you someinfo that points at the registrar
 
The only problem is with $student_id = mysql_insert_id();
It keeps incrementing
 
It's supposed to change, what do you mean?
 
5:15 AM
The student is one student
I want it to keep his ID
When a student signs up, it gives them an ID, say 1
 
so, quit trying to re-get it
 
Does the form you're submitting handle signup and registration for courses, or does it just signup the user?
 
I don't, it's out of the loop, but it keeps re-assigning valoue
Its both
 
unless @cHao knows what you're talking about, I'd have to see the code
 
values don't magically change.
 
5:17 AM
(preferrably on pastebin again)
 
either you're re-getting the id in the loop (and thus getting the last enrollment id), or....well...i dunno.
yeah...show us
 
There you go guys, thanks for the help.
 
Please, don't use mysql_* functions to write new code. They are no longer maintained and the community has begun deprecation process. See the red box? Instead you should learn about prepared statements and use either PDO or MySQLi. If you can't decide which, this article will help you. If you pick PDO, here is good tutorial.
 
@tereško we've told him numerous times
 
@cHao This in php?
 
5:19 AM
I know, Teresko! This is just a small thing and I'm going to change it later.
 
@AlexCastro ...i thought you said the mysql_insert_id() call was out of the loop? :P
 
@AlexCastro you're recalling mysql_insert_id() every time you run the loop
 
Wait what lol one second
ugh
lol sorry guys it's late
 
also, I'm sure @cHao has said it twice, get rid of the auto_increment field!!!!
it doesn't need to be in the query.
 
@ShyamK no...it's a tool commonly available from a *nix command line, and some web sites offer it too
 
5:20 AM
@cHao I don't need a terminal command to find that out.. I wanted something in php if possible..
 
@Nile auto_increment field where?
 
INSERT INTO students (ID,
and
 
@AlexCastro the ID field, in your insert into enrollments, should not be there.
 
INSERT INTO enrollments (ID
 
5:21 AM
I don't need to?
Oh cool
Thanks, the little things I dont know :p
 
if its set as auto increment then it's just superfluous in your code
 
Okay, thanks
 
also, just to double check: '$username', '$password', '$email' those values are being mysq_real_escape_string()'d, true?
 
worse than superfluous...it's actively harmful if you have some auto id's and other manual ones. queries fail when the id's collide
mysql doesn't check to make sure an id doesn't exist before it uses it
 
@Nile yes they are ;)
 
5:24 AM
okay, lack of prepare statements scare
 
haha
 
yeah...really. mysql_query sucks big fat hairy coconuts through a 50 foot straw.
start using prepared statements...you'll never want to cobble sql together by hand again
 
please just fix the code, it will take 5 minutes
 
lol I love how you guys are so bothered by it
Well, gimme a simple translation per say and I'll get it done.
 
per se*
 
5:26 AM
yes, it's late, again, haha
 
:P normally I wouldn't correct spelling but that one always bugs me for some reason
 
@AlexCastro you're lucky you're still on my good side. i have actively refused to help people with code that used mysql_query til they got rid of it.
 
haha I know it which sucks
 
and i'm close to doing so again...lol
 
@cHao I'm open to getting rid of it! Now's your chance!
 
5:27 AM
$query = $pdo->prepare("INSERT INTO students (username, password, email) VALUES(?, ?, ?)");
$query->execute(array($username, $password, $email));
is equivalent to that nasty line 2 you've got
 
with the question marks?
 
Yeah, you can use :variables also
 
how do I close a mysqli con?
 
$enroll = $pdo->prepare("INSERT INTO enrollments (student_id, course_id) VALUES (?,?)");
foreach ($_POST['classes'] as $course_id) {
    $enroll->execute(array($student_id, $course_id));
}
 
5:30 AM
mysqli's a little more complicated, but not terribly so
 
I like it
Can I mix a mysql query with mysqli?
I started the DB connection with mysql
 
$student_id = $pdo->lastInsertId();
No!
 
not that i know of
 
It's called OOP
 
the two are entirely different extensions...almost certainly not cross compatible
 
5:32 AM
Can you guys link me to a guide then? Don't want to riddle this with questions.
 
why are you considering the mysqli_*
 
You guys said that!
haha
 
go with PDO:: or mysqli::
 
I mean, if you're not willing to take the extra jump, it's better... But you can use objects!!
It's like choosing a stale brownie over a warm fresh one
 
5:34 AM
yeah...those are better, really. mysqli has a procedural api that's like mysql's, but if you stick to that you don't really get most of the benefits
 
Woops I mean PDO guide!
 
(vs. a moldy one = mysql_*)
 
cHao gave me a PDO example
$enroll = $pdo->prepare...
 
yeah..?
 
I need a guide as to how to open the connection with this toto
 
5:34 AM
shut up and read the damned article
 
Ah, thankns
 
btw $pdo = new PDO("mysql:some connection string", $username, $password);
 
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password');
 
that would be how you connect to a database through the PDO __construct
 
"try" automatically gets the latest connection?
 
5:38 AM
course, where we've been using $pdo in our examples, you'd use $db :)
 
ah okay cool
 
hey @ShyamK how's it going
 
pastebin.com/yS3Ruv2x this look good @Nile @cHao?
 
i wanna say, getData is one of the crappiest names ever for a function. :)
 
straight from the article
 
5:42 AM
Yes, Nile haha
 
but the connection to the database should probably be inside the try block as well
 
okay done
Now I'm all set with the connection?
 
You don't need the getData for the connection
plus you'd have to define getData()
 
Oh, okay
 
getData() was just a placeholder for your "do what you need with the database" code
 
some_logging_function() would also need to be defined
 
lol right
 
the code that does the queries should probably be within the try block too
 
you can just replace lines 7-8 with die($ex->getMessage()); for testing purposes
 
that'd work for now
 
5:45 AM
Okay so I'll try it then.
You guys sent me before
$enroll = $pdo->prepare(...
 
mhm
 
do I need the $variable = part?
 
you dont need the prepare statement if theres nothing to prepare
 
hmm okay
 
but using prepare statements you need to execute them somehow
if you're going to involve variables in the query, you need the prepare statement, so yess, you need the variable.
 
5:47 AM
yes..the $variable = is necessaryif you intend to do anything with the statement that gets prepared
 
but if there is no need for a prepare statement, you can just use ->query()
 
Okay so
to
mysql_query("INSERT INTO students (username, password, email) VALUES('$username', '$password', '$email') ") or die(mysql_error());
 
i told you how to do that already
 
$pdo->prepare("INSERT INTO students (username, password, email) VALUES ($username, $password, $email)");
Yes, is that right?
 
$query = $pdo->prepare("INSERT INTO students (username, password, email) VALUES(?, ?, ?)");
$query->execute(array($username, $password, $email));
 
5:49 AM
It cant be done in one?
 
hey... Going well.. hope you are doing well too....
Long time since I've seen Sam here.. the one who had a pink sort of gravtar..
@Nick What are you up to?
 
@AlexCastro, no. You need to execute the prepare statement.
 
@AlexCastro not if you want the code to not suck :)
well....
 
Haha
Okay thanks
 
simple no would be fine...
 
5:50 AM
@ShyamK yeah was going to ask you about Sam haha, it's going very well, finished my framework to some degree
 
$result = $pdo->prepare('INSERT...')->execute(args...);
 
> simple no would be fine...
 
but that's rather ugly
 
lol
 
bah...i keep using $pdo for thevariable name...lol
 
5:55 AM
$sql = $db->query("SELECT username from students where username='$user_check'");
please tell me its okay, haha
 
No!!!
 
damn
 
what happen to prepare statements? have we lost all sanity? only use queries when you don't need variables
 
I have the opening of the database above
the one I sent before
 
change query to prepare, replace the variable with either ? or :user_check, then either pass the $user_check in an array with execute or through bindParams
 
5:59 AM
I want an API to convert PDF to HTML in java
 

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