473,789 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

eragon
431 Contributor
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 1468
ManWithNoName
88 New Member
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 Contributor
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 Contributor
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 Contributor
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="thispag e.php" method="post">< input type="text" name="query"><i nput 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="thispag e.php" method="post">< input type="text" name="query"><i nput 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
66913
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 = array(array("First Name",$_POST),array("Surname"=>$_POST),array("Compan
1
3168
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: $myarray = $array(1, 2, 3, ... 100); echo 'Enter your changes, then click Submit:'; foreach ($array as $i) echo '<table tags> <input value="'.$i.'" name="index.'$i.'"> <table tags>';
6
10987
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 type='text' name='login' size='30'/> Password:<input type='password' name='login' size='30'/> </form>
4
7196
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: Undefined index: city in /home/www/reformcagunlaws.com/new.php on line 8 PHP Notice: Undefined index: county in /home/www/reformcagunlaws.com/new.php on line 9 PHP Notice: Undefined index: zip in /home/www/reformcagunlaws.com/new.php on line...
1
1212
by: Leszek | last post by:
Hi. I'm using <pre><?php print_r($_POST); ?> </pre> and i'm getting this: Array (
26
6299
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 of values to them based on data submitted from POST Fields. Code below: $_SESSION = array();
6
2726
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 action buttons, such as "Edit", "Add", and "Comment". Since I do not know how many rows of data will be retrieved - and therefore how many buttons I need - I am using button arrays for each button, like so: echo "<input type=\"submit\"...
3
2062
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 these two undefined index error : Notice: Undefined index: CurrentCustomer in E:\WebSites\mysite\www \contactus.php on line 9 Notice: Undefined index: ContactMethod in E:\WebSites\mysite\www \contactus.php on line 19
16
6569
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"> <tr> <td colspan="2">Pesonal Info Table 1 </td> </tr> <tr>
0
10374
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5405
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5540
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4078
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2898
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.