How to?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

infomorelos
New php-forum User
New php-forum User
Posts: 14
Joined: Mon Jan 27, 2003 12:10 am
Location: Cuernavaca, Mexico

How to?

Postby infomorelos » Sat Feb 01, 2003 1:09 am

I would like to find out how I can evaluate the result of an addition with php.

the idea is

5+6=?

if the user writes '11' into a form field and clics on 'submit',
a message should say: 'Correct!'

else

the message should say: 'Wrong!'

I fantasise that the basic structure could be:

<? php
if
echo
}
else
echo
}
?>

Thank you in advance

TheIceman5
New php-forum User
New php-forum User
Posts: 28
Joined: Tue Jan 21, 2003 9:31 pm
Contact:

Postby TheIceman5 » Sat Feb 01, 2003 5:00 am

huh? i make out of it this,

<? php
if(5+6==$_REQUEST["form_field"]){
echo "correct";
}
else {
echo "Wrong";
}
?>

infomorelos
New php-forum User
New php-forum User
Posts: 14
Joined: Mon Jan 27, 2003 12:10 am
Location: Cuernavaca, Mexico

That doesn't seem to work

Postby infomorelos » Sun Feb 02, 2003 10:07 pm

I inserted your code on this 'testt.php' page:
<html>
<head>
<title>Ich teste</title>
</head>
<body>

<? php
if(1000+40+1000+30+1000+20+1000+10==$_REQUEST["form_field"]){
echo "correct";
}
else {
echo "Wrong";
}
?>
<form name="form1" method="post" action="testt.php">
<p><font size="2">1000</font></p>
<p><font size="2">+</font></p>
<p><font size="2">40</font></p>
<p><font size="2">+</font></p>
<p><font size="2">1000</font></p>
<p><font size="2">+</font></p>
<p><font size="2">30</font></p>
<p><font size="2">+</font></p>
<p><font size="2">1000</font></p>
<p><font size="2">+</font></p>
<p><font size="2">20</font></p>
<p><font size="2">+</font></p>
<p><font size="2">1000</font></p>
<p><font size="2">+</font></p>
<p><font size="2">10</font></p>
<p>
<input type="text" name="form_field">
</p>
<p>
<input type="submit" name="Submit" value="Verificar resultado">
</p>
</form>

</body>
</html>

However, I get:
Parse error: parse error, unexpected T_IF in /usr/home/infomorelos/public_html/kids/testt.php on line 8

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Sun Feb 02, 2003 10:20 pm

<?php not <? php


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest