473,657 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do i extract values from an array to show on a html page

74 New Member
hello,

im trying to build an application that will incorporate a "forgot password" feature. in order for my feature to work correctly, i am asking the user to type in his/her email address and he/she will have to answer a security question.

Expand|Select|Wrap|Line Numbers
  1. <form id="form1" name="form1" method="get" action="emailRetrieve.php" >
  2.         <label>Please enter your email address:</label><br/>
  3.           <label> Email address: <input type="text" name="emailText" id="emailText" size="50" /><br/><br/>
  4.  
  5.               Secret Question: <br/>
  6.               Secret Answer: <input type="text" name="secretAnswer" id="secretAnswer" size="49" /><br/>
  7.  
  8.         </label>
  9.         <input type="submit" value="Submit"/>
  10.         </label>
  11.     </form>
  12.  
in my php script, i created an array with only 3 questions. Every time the page is refreshed, or other users use the "forgot password" feature, i am implementing a random function which chooses a random index of the array and will hence display a different question every time.

my problem is, when i hardcode the php script into the html page right after the "Secret Question" it works perfectly fine and i see the questions randomly changing when the page is refreshed. The problem now is that i need to send that same question for verification in my database. I can not access this variable outside the .html page. Now, when i move the php block to another file, i can not randomly generate my question and insert it into the html page. i know i have to use the $_POST method but whatever i try is not working

can anyone shed some light on this? how to i use php to randomly generate an index in my array and then insert it into my html page?

the code that im using for my 3 random questions is:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  <?php
  3.  
  4. $securQueArr = array("1" => "what was your first car", "2" => "what is your mothers name", "3" => "which city were you born in");
  5. $randInt = rand(1,3);
  6.  
  7.  
  8. $securityQuestion = $securQueArr[$randInt];
  9.  
  10. ?> 
  11.  
  12. any ideas?
  13.  
  14.  
Aug 2 '10 #1
5 2140
TheServant
1,168 Recognized Expert Top Contributor
In your form you need something like:
Expand|Select|Wrap|Line Numbers
  1. <p>Secret Question: <?php echo $securityQuestion; ?></p>
To display the question.

You will also need to send the $securityQuesti on through to your processing script which can either be done with $_SESSION's or $_POST. I am going to recommend $_POST (which is less secure) because all you're doing is sending the question. To do that, I suggest having a hidden input with the question number as the value:
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="Q_Num" value="<?php echo $randInt; ?>" />
Then in your processing script you can get the question number used like:
Expand|Select|Wrap|Line Numbers
  1. // Validation of $_POST variables
  2. $Q_Num = $_POST['Q_Num'];
Aug 3 '10 #2
rotaryfreak
74 New Member
it seems to be almost working :| i get an error:
Notice: Undefined variable: securityQuestio n in C:\Program Files\Wamp Server\www\Movi e Database\EmailP wd.php on line 20

and when i look at line 20, it's this line:

Secret Question: <?php echo $securityQuesti on; ?>

strange because i do define the value in my script...but, at least now im getting some input after Security Question

any ideas?
Aug 3 '10 #3
TheServant
1,168 Recognized Expert Top Contributor
Are you defining it above that line? Is the case all the same? If yes to both of those, post your page code and let me have a look.
Aug 3 '10 #4
rotaryfreak
74 New Member
:) worked perfectly. here's what i did. After you asked if it was defined, i included the entire php script above the Secret Question line, and modified my emailRetrieve.p hp $Q_Num = $_POST['Q_Num']; to $Q_Num = $_GET['Q_Num'];
now my question changed randomly AND i have access to it through my emailRetrieve.p hp script so i can validate it against the entry in my database. Everything works perfectly, thank you so much!
Aug 3 '10 #5
TheServant
1,168 Recognized Expert Top Contributor
No problem, glad it works.

Didn't notice your form method was GET, but, if you're happy with that, then great ;)
Aug 3 '10 #6

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

Similar topics

4
21056
by: Guogang | last post by:
Hi, I need to extract plain text from HTML page (i.e. do not show images, html formatting, ...) Is there some C# class/function that can help me on this? Thanks, Guogang
2
1733
by: drawbridgej | last post by:
I've done a little xml and xsl, but am a relative newbie. I have been unable to find a stylesheet to process an xml file and output the tagNames and tagValues in HTML. I have also posted this message in tek-tips. I can get the node names with name() and the value with xsl:value-of .... but I would like to get the lowest level tagNames via the xsl. I'd like to be able to build html for a number of different xml files.
3
2450
by: rahman | last post by:
I have few hundred HTML pages. I need to extract portion of each HTML page into a text/database/HTML files format. You can imagine it is very tedious to do one by one. Is there any automatic process/software/tool available that could help me extract information form mass HTML files? I can specify what portion of file to take or leave. I have some tag like: <!--topic start-->
0
1110
by: uto | last post by:
i'd like to attach some aspx page in HTML template HTML template consist of Header,Content and Footer. i just wanna show Html page appear consist of Header, aspx page and Footer is it possible ?
1
2450
by: spree | last post by:
Hii everybody, here is my question I have values(for ex-username and password) in one html page. so after enters the values and clicks the submit button i am able to forward to next html page " action" in the form tag, but how to display a message in the 2nd page like.... therefore your username is:..........( the value he submitted in the 1st html page) using javascript or html. Thanks in advance...
7
4288
by: cartercc | last post by:
I think I already know the answer to this one, but I'm giving it the old college try. My problem is this: I have an HTML form that sends a bunch of data to a Perl script, where it is validated and read into a database. The powers that be have decided in their infinite wisdom that the initial page needs to be broken into two parts. (This is an attempt to correct some common user errors, not because of any technical reasons.) So I'm...
6
3560
kamill
by: kamill | last post by:
Ineed to extract images from html page using regular expression, but am not able to get desired result. help me. Bellow is my code <?php $site='http://www.gmail.com'; $str_text = file_get_contents($site); function str_img_src($html) { if (strpos($html, '<img') !== false) {
2
1902
by: jayachandrav | last post by:
Hello, How to pass values from the html page to the codebehind of the same page. Thanks for advance, JC.
1
1457
by: majid091 | last post by:
Hello, i want to extract only st paragraph of html page, only text not the images in the preview window when ever some one move the cursor to the link. Any solution ?
5
2683
by: amkohl | last post by:
<script type="text/javascript">dcsMultiTrack('DCS.dcsuri','/a/b/c/d/e','DCS.dcsqry','_ABC=ABC_0001','DCSext.error_code','abc500','DCSext.error_desc','FAILURE','DCSext.error_type','ABC Error','DCSext.RegType','ABC Registration','DCSext.RegStep','ABC Entry');</script> Suppose, there is a script with dcsMultiTrack method with its comma seperated values in the HTML page (as shown above). Is it possible to fetch each of these comma seperated...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
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...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4171
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
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
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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.