473,412 Members | 4,957 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,412 software developers and data experts.

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

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

✓ answered by TheServant

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 $securityQuestion 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'];

5 2128
TheServant
1,168 Expert 1GB
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 $securityQuestion 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
it seems to be almost working :| i get an error:
Notice: Undefined variable: securityQuestion in C:\Program Files\Wamp Server\www\Movie Database\EmailPwd.php on line 20

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

Secret Question: <?php echo $securityQuestion; ?>

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 Expert 1GB
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
:) 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.php $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.php 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 Expert 1GB
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
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
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...
3
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...
0
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...
1
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 "...
7
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...
6
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 =...
2
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
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
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...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.