Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
I Have Problem With "if"
Old 09-23-2008, 03:40 AM I Have Problem With "if"
Novice Talker

Posts: 4
Name: dhakalall chhetri
Trades: 0
when i place this code:
<?php
$a=strip_tags(trim($_POST[roll_no]));
if ($a=="")
{
echo "<B><font color='red' size='3'><CENTER>YOU MUST ENTER ROLL NUMBER</CENTER></B></FONT>";
}
?>

IT WORKS FINE,
BUT WHEN I ADD THIS CODE:

<?php
$a=strip_tags(trim($_POST[roll_no]));
if ($a=="")
{
echo "<B><font color='red' size='3'><CENTER>YOU MUST ENTER ROLL NUMBER</CENTER></B></FONT>";
{
if ($a<>ereg("^[0-9]")
{
echo "enter number only";
}
}
}
?>
IT SAYS PARSE ERROR UNEXPECTED '{' ON LINE '8', CAN ANYONE HELP ME,WHERE I DID MISTAKE

Last edited by hotstar07; 09-23-2008 at 03:59 AM..
hotstar07 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-23-2008, 05:03 AM Re: I Have Problem With "if"
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
you havent closed the first IF statement's curly brackets. After the line "echo "<b>..." change the open curly brackets to closed.

You might be after an "elseif" statement in which case it should look like this:

PHP Code:
if( == )
{
//do something
}
elseif( 
== )
{
//do something else
}
else
{
//do another thing

stoot98 is offline
Reply With Quote
View Public Profile
 
Old 09-23-2008, 05:34 AM Re: I Have Problem With "if"
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Your conditionals are not correctly braced and your ereg does not have the correct parameters. http://uk3.php.net/ereg

Try
PHP Code:
$a=strip_tags(trim($_POST['roll_no']));
if (
$a=="")
{
echo 
"<B><font color='red' size='3'><CENTER>YOU MUST ENTER ROLL NUMBER</CENTER></B></FONT>";
}
if (
ereg('[^0-9]'$a)) {

echo 
"You entered $a , please enter number only";

maxxximus is offline
Reply With Quote
View Public Profile
 
Old 09-23-2008, 11:15 AM Re: I Have Problem With "if"
ndr
ndr's Avatar
Novice Talker

Posts: 9
Trades: 0
BTW, the code you posted doesn't really need any curly braces. But I advise you to indent it properly, making it more readable.
__________________

Please login or register to view this content. Registration is FREE
- help surfers find your pages after an address change!
Free and ad-free!
ndr is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to I Have Problem With "if"
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31547 seconds with 12 queries