473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Calling an array with a string as it's index... $($_Post...)['email']

eragon
431 256MB
ok, the title was not proper syntax at all.

heres what i did. for every user that registers for my site their information is stored in an array. their userame is the index. the data i want is the key. one example i share is this:

[php]
<?php
$eragon['password'] = "password" ;
$eragon['f-name'] = "Eragon" ;
$eragon['l-name'] = "Eisert" ;
$eragon['email'] = "omitted@forum.rules" ;
$eragon['notes'] = "ADMIN" ;
?>
[/php]

and to retreive the info i send in a post request with only the username (eragon) and wish it to echo the value of that part of an array. Could somebody please help? Please?

Sincerely,
Eragon
Nov 25 '07 #1
4 1455
I think the magic word is... Well, I forgot the magic word, but I do remember the symbols that made it up, try :
[PHP]
$eragon = 'user007';

${eragon}['password'] = "password";[/PHP]

Does that juice you up?
Nov 25 '07 #2
eragon
431 256MB
lol. 007.

Ok, i see that, nice, very well, but... may i ask... how in entirety am i supposed to do this? where does your code go in?

heres the two parts: the array above and the form.

[___________] {Submit} and thats all thats in the form. the text field is named query, and passes its information through $_POST. i included the file containing the arrays. maybe i should have a better method of storing? and whats the purpose of the $eragon = "user007" ? i know php but im still learning. meh, could you be a tad bit more specific. please? im at a loss... for now, idk... il lhave it rite to a file and il linclude the file that will echo, but that may take a little while... i dont know, any help would be appreciated... maybe str_replace? idk
Nov 25 '07 #3
eragon
431 256MB
wait a minute! Can i put the string in replace of the key? and have just a integer as the key? so i can have arrays that look like this:

[php]
<?
$user['eragon'][0] = "password" ;
$user['eragon'][1] = "omitted@forum.rules" ;
// ...
print_r($user) ; //will print ALL the information, which can come in handy.

echo($user[$_POST['query']][0]) ; //is a recipie for disaster...

//and thats how i think it might work...

?>
[/php]
Nov 25 '07 #4
eragon
431 256MB
ladies and genties, i have found a solution! make the index of the array a simple string, any string, whether it be yarn or thread, and the first key of the array the username. the second key of the array is the info stored in that array. or you can make the index the info and the key the username, and not need anything else: but remember, you CAN make the key's value equal to a get or post string because the key does not have the $ tag, so the value will be inserted. heres how you call it then:

[php]
<?
//method a: the array.
$user['eragon']['email'] = "omitted@forum.rules" ;
$user['eragon']['password'] = "passer-word" ;
$user['saphira']['password'] = "sappy-fire" ;

//Method a: the calling.
echo('<form action="thispage.php" method="post"><input type="text" name="query"><input type="submit" value="Get \'Er Done!"></form>');
if(isset($_POST['submit'])) {
echo($user[$_POST['query']]['email']);
echo($user[$_POST['query']]['password']); }

//-----

//Method B: the array.
$emails['eragon'] = "e's email" ;
$passes['eragon'] = "e's pass" ;
$passes['saphira'] = "s' pass" ;

//Method B: the calling.
echo('<form action="thispage.php" method="post"><input type="text" name="query"><input type="submit" value="Get \'Er Done!"></form>');
if(isset($_POST['submit'])) {
echo($emails[$_POST['query']]);
echo($passes[$_POST['query']]); }

//and the funny php closing tag
?>
[/php]

so thas why everything, every last little thing, every little tiny microscopic little thing has goooooone... according to plan!

should i make this an article?
Nov 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Keiron Waites | last post by:
I get the following error: Notice: Array to string conversion in C:\Documents and Settings\ShepMode\Desktop\Websites\ShareMonkey.net\Web\join.php on line 11 in this code: $input =...
1
by: Raptor | last post by:
I'm using a single script to generate a table with <input>s in each row. I fill the array with initial values, then write it out to the table and let the user edit the values. Something like: ...
6
by: brian_mckracken | last post by:
This might not be the right group for this question, since its kind of a pure html question... Given the html construct: <form action='index.php?expand=0,10000' method='post'> Email: <input...
4
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: ...
1
by: Leszek | last post by:
Hi. I'm using <pre><?php print_r($_POST); ?> </pre> and i'm getting this: Array (
26
by: drako | last post by:
Hi, I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set...
6
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
3
by: JJM0926 | last post by:
I've got a contact form with a submit button where users have to enter their support information. Some fields are required some are not. When I test out the form if I leave everything blank I get...
16
luckysanj
by: luckysanj | last post by:
For example i have two files one in index.php & another is check.php. index.php <body> <form id="form1" name="form1" method="post" action="check.php?id=tbl1"> <table width="200" border="1"> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.