Jump to content

for loop


helpmehelpmehelpme

Recommended Posts

I have this script that asks the user their name and email address and age and stuff and it checks to see what their age is and outputs a message depending on what age bracket they belong to.  I am trying to make a for loop that uses the value the user submitted for their age and output the range of numbers from the users age to 1000 by 3s, i know how the basic for loop works, but i don't know how to do one where you are using a variable for i. if that makes sense. Heres the code that i have.

test1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Feedback Form</title>
</head>
<body>
<div><p>Please complete this form to submit your feedback:</p>

<form action="test1.php" method="post">

<p>Name: <select name="title">
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
</select> <input type="text" name="name" size="20" /></p>

<p>Email Address: <input type="text" name="email" size="20" /></p>
<p>Age: <input type="text" name="age" size="20" /></p>


<p>Response: This is...	
<input type="radio" name="response" value="excellent" /> excellent
<input type="radio" name="response" value="okay" /> okay
<input type="radio" name="response" value="boring" /> boring</p>

<p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p>

<input type="submit" name="submit" value="Send My Feedback" />

</form>
</div>
</body>
</html>

test1.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Your Feedback</title>
</head>
<body>
<?php 
include('test1.html');
$name = $_POST['name'];
$age = $_POST['age'];
$okay = TRUE;

if(empty($name)){
echo '<p class="error"> Please enter your name.</p>';
$okay = FALSE;
}
if (empty($age)){
echo '<p class="error"> Please enter you age.</p>';
$okay = FALSE;
}

if ($age < 65){
echo '<p>no retirement for you</p>';
}
if ($age == 65){
echo '<p> Yay, you can retire</p>';
}
if ($age > 65 || $age < 100){
echo '<p>Florida is for me!</p>';
}
if ($age > 100){
echo '<p>Good Genes</p>';
}

//print users age to 1000 by 3s
for($i=$age; $<1000 i+3){
echo '$age';
}

?>

</body>
</html>

Link to comment
Share on other sites

right, but i keep getting error messages

$age

Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38

$age

Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38

$age

Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38

$age

Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38

$age

Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38

$age

Link to comment
Share on other sites

heres the updated code

test1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Feedback Form</title>
</head>
<body>
<div><p>Please complete this form to submit your feedback:</p>

<form action="test1.php" method="post">

<p>Name: <select name="title">
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
</select> <input type="text" name="name" size="20" /></p>

<p>Email Address: <input type="text" name="email" size="20" /></p>
<p>Age: <input type="text" name="age" size="20" /></p>


<p>Response: This is...	
<input type="radio" name="response" value="excellent" /> excellent
<input type="radio" name="response" value="okay" /> okay
<input type="radio" name="response" value="boring" /> boring</p>

<p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p>

<input type="submit" name="submit" value="Send My Feedback" />

</form>
</div>
</body>
</html>

test1.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Your Feedback</title>
</head>
<body>
<?php 
include('test1.html');
$name = $_POST['name'];
$age = $_POST['age'];
$okay = TRUE;
$i = $_POST['age'];

if(empty($name)){
echo '<p class="error"> Please enter your name.</p>';
$okay = FALSE;
}
if (empty($age)){
echo '<p class="error"> Please enter you age.</p>';
$okay = FALSE;
}

if ($age < 65){
echo '<p>no retirement for you</p>';
}
if ($age == 65){
echo '<p> Yay, you can retire</p>';
}
if ($age > 65 && $age < 100){
echo '<p>Florida is for me!</p>';
}
if ($age > 100){
echo '<p>Good Genes</p>';
}

//print users age to 1000 by 3s
for($i=$age; $i<1000;$i+3){
echo $age;
}

?>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.