I hate PHP. lol

Status
Not open for further replies.

bam bam

New member
Oct 9, 2007
962
11
0
So, i'm trying to insert usernames from an <input type=text" name="user"> into an array. But it doesn't work.

This works:

HTML:
$username = array(username1, username2, username3);
foreach ($username as $value) {

etc etc
This doesn't (text box has the following in it - username1, username2, username3):

HTML:
$username = array($_POST['user']);
foreach ($username as $value) { 

etc etc
I really want to get this to work as it's the last part of my first PHP script.

Ideally i would have the usernames posted into the array via a textarea with each username on a seperate line.
I tried it this way using explode() etc, but i couldn't get it to work. So this is my backup plan.

Any ideas?
 


What is the seperator?
If s comma's try doing this:
Code:
$username = explode(',', $username);
foreach ($username as $value) {
trim($value);

etc...
 
HTML:
$username = array($_POST['user']);
This line is a little odd. You seem to be defining an array here with one element (the single element being the $_POST['user'] value.

If $_POST['user'] is coming in as an array (and it needs to be defined as such in the html form) then you could just do $username = $_POST['user'].

To be honest I'm not entirely sure what you're trying to do, though. Maybe you could post the form and the relevant php?
 
  • Like
Reactions: bam bam
instead of
<input type="text" name="username" />
<input type="text" name="username" />
<input type="text" name="username" />

try this:
<input type="text" name="username[]" />
<input type="text" name="username[]" />
<input type="text" name="username[]" />

untested, i dont really understand what you are trying to do...
 
nis is right. You'll need to "explode" the comma-separated string into an array. Passing the string as a parameter to array() would just create an array with one value containing that string.

And if you need to explode the value from a textarea where the data is separated by new lines:

$array = explode("\n", $_POST['textareaname']);
 
@ bam, PHP hates you! You tried the explode(stuff); I dont buy it! Next time you already know the solution, google it (php dot net/explode) and learn to use it!
 
@nohatter WTF is wrong with you?

As a developer you KNOW you hit the wall sometimes. The easy peasy solution just eludes you until someone comes along, telling you "duuuh".

As a beginner / intermediate it happens more often, but even the pros need help sometimes.

::emp::
 
I usually post a question somewhere and then promptly finds the answer myself.
 
@nohatter WTF is wrong with you?

As a developer you KNOW you hit the wall sometimes. The easy peasy solution just eludes you until someone comes along, telling you "duuuh".

As a beginner / intermediate it happens more often, but even the pros need help sometimes.

::emp::

First of all, im no developer. I was not very serious with my answer to this thread. However, i must say that i think he didnt take his time to study his issue and thought asking here would be quick and dirty way to get his answer. Dirty it was, in a way, that the answers were from arse. I've seen this guy doing php here before, like, giving away scripts and stuff, and now he cant solve this on his own. C'mon.

@Bam, i was not trying to to be mean or anything, i just thought you got lazy and
gave you a little push. BOOM you went over the edge!!
 
@nohatter

I see. Word of advice - if you are no developer, stop talking out of your ass around people trying to code.

::emp::
 
@nohatter

I see. Word of advice - if you are no developer, stop talking out of your ass around people trying to code.

::emp::

Whats your problem? Man im from finland, your fancy words like "developer" means shit to me. I know how to code, and do if i need to. Don't take no fancy nerd titles to put together oneliners, baby! I know it's hard to admit that i had a point here. You just could'nt stop at "I See", check yourself!
 
@nohatter.. I just do not take shit.. not anyones.

So you are from finland? So what?

If you really were a coder, you would know how it is to hit that block. To not get anywhere with your code, despite trying.
Bam Bam, a nice and helpful member of this forum was being shit-talked by a noob like you. About something I care about.

Maybe I was over the edge, but man, you can just go and check your lines to see why.

If you really need to talk about this some more, chat with me at empKAZ (AIM) or captainklinge (skype).

Else I will see this as ended.

::emp::
 
@nohatter.. I just do not take shit.. not anyones.

So you are from finland? So what?

If you really were a coder, you would know how it is to hit that block. To not get anywhere with your code, despite trying.
Bam Bam, a nice and helpful member of this forum was being shit-talked by a noob like you. About something I care about.

Maybe I was over the edge, but man, you can just go and check your lines to see why.

If you really need to talk about this some more, chat with me at empKAZ (AIM) or captainklinge (skype).

Else I will see this as ended.

::emp::

Ok. I understand your love for your boy. No-one fucks with my figgas either. Perhaps there was a language barrier here, so i apologize my bad english. The finland thing was,
that i dont know what the word "developer" means btw. I agree, lets end this here, since his problem is solved and theres some emotional stuff in the air.

Take care.
 
@bam bam, your new signature is not really needed now is it boy? Did i really piss you off that much? It was still you who sent this stupid ass question in "newbs" and not "coding" and so on.

So you think that just because emp is a huge fanboy of yours, you dont deserve flames when you ask ridiculous questions here like everyone else?

What really gave you this amazing god status here anyways? It's not your coding skills, thats for sure!

So please quit acting like emo girl and take it easy. I made one comment about your fool ass question and you went as far as buying someone to code you a signature that is supposed to make me mad. yousa silly dude!

So, im superb sorry that my comment set you off and hope that you could get over it. Theres really no need to take this any further by doing stupid signature shit. Take care!

I dare to ask, IS this the BEST you can do?
<?php
mysql_connect("death", "grim", "reaper");
mysql_select_db("death");
if($name="nohatter"){
header("Location: grave");
}
?>​
 
Last edited:
Troll Troll Troll your boat.

I have no idea what "Troll" means, but i guess it's another one of those fancy geek words
used to determine a person who is doing something wrong in forums.

If it has anything to do with inspiring others into some internet girl fight, then i guess your post was not too far from it and could easily be set as an example.

Could you point me what part of my post made it "Troll"?

Anyhow, the original objective of this thread has already been reached, and now im just trying to help
a fela who's feelings were hurt by my "cruel insults" towards him. I thought it would be nice to do it public, but it seems i was wrong on this one also. Internet is so much different from real life..

Im basically trying to get one to man up if you didnt catch that. I thought wickedfire
was known from comments like my original was on this thread, correct me if im wrong. I was just trying to play along, and the results were horrifying. internetseriousbusiness horrifying that is!

This very thread was useless from the beginning but now i hope that it atleast gives some entertaining value. Or perhaps even remind some "internet success guy" that he should not be treated different from others and he/her might be getting too high from his shit :rasta:
 
Status
Not open for further replies.