logs archiveIRC Archive / Freenode / #php / 2006 / June / 7 / 12
philip
lies
richardlynch
Probably just means you have an intermittent bug. :-)
Zakabog
haha
Probably
MariusX
hello ppl. I am wanting to create a simple registration form that takes the fields entered, check to see if they pass validation and add the user to the database. I want the form to reload showing the fields that didn't pass validation to show up read.
can anyone help me do this or point me to a good script or tutorial?
Zakabog
And I hacked out a ton of stuff from a table all in emacs and redid it kind of guessing a way it'd look nice and it also just worked and looked pretty
philip
must have loaded a cache version ;)
Zakabog
lol
richardlynch
MariusX: Google for PHP MySQL authentication tutorial.
Zakabog
I'm afraid, very very afraid
I'm going to touch something on the page and the webserver's going to burst into flames
         

MariusX
richardlynch: I know how to do a sign in form. I need to know how to have a registration form.
richardlynch
MariusX: Change the SELECT query to an INSERT? If you actually understand the sign in form, it's a no-brainer...
Zakabog
MariusX it should be the same thing except you're inserting a row into the database with the user's info
Hehe
richardlynch
Sorry -- that may have sounded negative. I'm saying it will be a lot easier than you think, not that you shouldn't need help.
sal002
Anyone here decent with preg_split?
I have a text string like this "Array ("test", "test2")" - I want to get this into an actual array
MariusX
I can also create a very basic form that adds a user. I want to be able to validate the fields, if they dont validate then reload the same page with the firled highlighted and they have the user fix them then add to database
zircu
sal002: it all depends on what you want to do
MariusX
want to be able to do it all inside the one page
richardlynch
MariusX: You've just described about an hours' worth of work, but not a question... We're not gonna sit down and type it for you...
sal002
string is actual "blah blah new Array("test", "test"), blah blah
richardlynch
MariusX: Perhaps Google for PHP MySQL user registration instead of authentication.
MariusX
thanks for the hugh amount of help. I have been googleing for hours.
zircu
sal002: that is more than a preg_split
sal002
zircu: That's what I feared....is there an easy way to do it?
philip
MariusX: a lot of if statements :)
richardlynch
sal002: preg_match_all("/Array\((\"([^\"]*)\"(, |\))/", $string, $data); var_dump($data);
sal002: That ain't right, but it's kinda close starter... Download The Regex Coach and play with it.
sal002
Okay! Thanks!
zircu
sal002: well i would think you might want to pass the data in a easier way
sal002
I would too - but that is the hand I have been dealt
zircu
sal002: then a method like richardlynch's is a good start
         

sal002
Yes.
richardlynch: thank you so much!
borland
hey - using array_map, can I set the key of the resulting array as well?
ie: how does array_map handle associative arrays - as far as I can tell it just plain doesn't
richardlynch
borland: Probably not, but using array_walk you could build a new array with different keys. You can't muck with the original array, though, without getting "unpredictable results" :-)
philip
anyone feel like sending me a pgp encrypted email so i can test my new setup? thanks :)
borland
hrmmmmmm
I'll write a proper array_map using array_walk
thx
TheNinthCut
I'm not getting the whole "continue" and "break" thing on the PHP manual. Would anyone know some documentation that could help explain this better.
borland
TheNinthCut: ??
continue and break are the same as in every other language
philip
break breaks the loop, continue continues to the beginning of the loop
(continues as in skips the part after the continue)
try the examples :)
richardlynch
Except break jumps to after the END of the loop
philip
php 6 will have goto, so you won't have to worry ;)
Pollita
WOOO!
GOTO!
philip
Pollita is the GOTO Goddess :)
borland
goto owns
xshad
are you talking about pascal ? O.o
richardlynch
I hope it's not documented, so all the newbies don't abuse it. :-)
TheNinthCut
It jointly applies to if else statements whiles and switches nested regardless right?
philip
no
borland
no only loops and switches
not if/else
TheNinthCut
Oh ok. That's helps a lot.
richardlynch
You can also do "break 2" and jump out of TWO nested loops. (or switch/loop or loop/switch or TWO switch)
borland
a continue on a switch is conceptually pointless, but PHP does support it - in that case it does the same thing as a break
"break 2" seems like a dumb thing...
philip
not really
richardlynch
borland: Hmmm... Does continue re-start the switch?...
borland: for ($x = 0; $x < $width; $x++) for ($y = 0; $y < $height; $y++) if (found_pixel($image)) break 2;
borland
don't think so
no
richardlynch
s/$image/$image, $x, $y/
borland
richardlynch: return and a function is better :-)
continuing a switch just breaks it according to the manual
richardlynch
borland: Yes, but then (except for switch) break and continue are usually a Bad Idea... Almost as bad as Goto. :-)
borland
richardlynch: you'd be wrong on that count
richardlynch
How odd... I mean, I guess I can see that, but if I was gonna bother to support continue in a switch, I'd have it start the tests over again from the top... Oh well. Executive decision.
borland
what's wrong with break and continue
richardlynch
break and continue, used sparingly, for specific reasons, are fine... But used a LOT end up with spaghetti code that is hard to follow. Like the example I tossed off.
maybe :-)
borland
heh, nar your example is only spaghetti code cos it uses break 2 - thus proving my point that break 2 is a bad idea :-)
richardlynch
I think the spaghettiness of a break 2 in a one-liner to rip through 2 dimensions x/y is pretty low. [shrug]
zircu
heh.. i just wrote some code that used a break 2
sal002
richardlynch: Is there a way to pull it out without regular expressions?
richardlynch
But is it good code?
sal002: Maybe explode("Array(", $text) to get started...
zircu
of course, it is the only way i could get a similar goto label; effect
sal002
thanks - Regex Coach was getting me more confused ;)
zircu
a do { } while(false); loop with some extra checking inside there
and commented on what is going on
s|k
function arguments pass pointers to objects in PHP5 right? not copies of objects right?
richardlynch
s|k: Yes, but call them references instead of pointers, to be pedantic.
s|k
what is the difference?
richardlynch
PHP doesn't have pointers. :-)
s|k
oh
zircu
s|k: cause you will confuse them like C pointers
s|k
okay thanks
zircu
but technically more, objects aren't passed by reference
s|k
eh?
richardlynch
Exactly what a reference is, and isn't, and how it's not a pointer is best explained in the manual.
zircu
variables in php are references to objects, when all variables referencing the object are destroyed the object is destructed
s|k
awesome, that's what I wanted
and that calls the __destruct
zircu
yes
s|k
I am planning on writing the changes to the object's members to the database when destruct is called
zircu
be careful on relyingon i would be careful with relying on __destruct to do that
richardlynch
s|k: Are you counting on PHP cleanup of objects/references to happen in the order you want? Don't.
zircu
heh.. backspace issues
s|k
uh oh
okay so much for that idea then
richardlynch
You should assume that PHP is gonna nuke your db connection BEFORE it nukes all your objects... even if it won't, it's not documented feature to not do that.
s|k
man that would have made it so somple
zircu
if you want your destructor to do important stuff you should be sure to destroy/unset/null all vars that reference it before php ends
richardlynch
s|k: Yes. YOU could do it by coding a call to db_write() or somesuch yourself, though.
Dorphalsig
Hi. I am running mod_apache2 on a win2k SP4, its NOT configured to run in safe mode
richardlynch
Or doing a destroy, but once you've done the work to track them all, relying on the magic of __destroy() instead ofjust calling db_write seems less clear, to me.
Dorphalsig
however, oddly enough I allways get an error when trying to create a dir
s|k
yeah good point
AfroTurf
is there a problem doing this $result = mysql_query($sql); while($foo = mysql_fetch_assoc($result)) { $result= mysql_query($sql); }, or do i have to name my vars something different inside the loop?
strav
he... I'm having a headache right here. I've got a simple script that adds categories... the freakin thing won't work in explorer. Though, the page is xhtml strict, and the code seems to work perfectly in firefox/mozilla...
zircu
AfroTurf: differently
AfroTurf
zircu: thanks
strav
if anyone with internet explorer could give me a hand, will be much appreciated: http://strav.dnsalias.org/roussil/admin/templates/tpl_categories.php
s|k
thank you for the informatoin richardlynch and zircu :)
richardlynch
Dorphalsig: Are you gonna tell us WHAT error, or you expect us to guess?
s|k
information even
richardlynch
strav: Perhaps #html would be a better forum... There's no PHP involved in the browser compatibility.
Dorphalsig
richard --> it says it cant create them. Ex Smarty
strav
lynch... I know that, you're right. thanks
richardlynch
Does it say "because safe_mode is on"?
Dorphalsig
Smarty error: problem writing temporary file '/tmp\%%331\%%33169576\448640d86f2a2'
zircu
Dorphalsig: hmm.. #smarty?
Dorphalsig
Reviewing in forums I see its a problem with directories and safe mode
richardlynch
Okay. So that's a Smarty error, which you need to address in #smarty and it will probably boil down to directories and permissions, and may or may not involve safe_mode
TheNinthCut
I never really understood the point of the header(content-type) stuff.
AfroTurf
TheNinthCut: images :)
sw0rdz
I am having a brain fart..I need a quick reminder on how to use an array with checkboxes
richardlynch
TheNinthCut: Suppose that PHP isn't constrained to outputting JUST html, but could also, say, draw an image on the fly. The browser needs to be "told" that the image is, well, an image, and not HTML. header("Content-type: ") tells the browser what kind of document it is getting.
AfroTurf
sw0rdz: array[]
sw0rdz
is it <input type="checkbox" value="array[]">
philip
php.net/faq.html
name, not value
AfroTurf
name
richardlynch
sw0rdz: name="array[key]" value="value"
sw0rdz
oh ok
thanks
philip
faq exists though :)
richardlynch
I always LOVE it when I get to us the key in the name= and PHP just does the right thing. My fave feature.
TheNinthCut
richardlynch, what If I'm just saving the image to my server and not manipulating it, then I don't need a header.
AfroTurf
TheNinthCut: depends on how your doing it, but generally no
richardlynch
TheNinthCut: Yes -- If you are not sending the image out to the browser, and you are saving it into a file, then you do not want/need the header("Content-type:") at all.
« prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 next »