SunQuest
 
           General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old December 1st, 2002, 02:32 PM
cemlouis cemlouis is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 49 cemlouis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Question Not working if???

i have a if statement which doesn't work which is:

include("../db_funcs/dbconnect.inc");


if(!$cat_name || !$lang_select)
echo "Please enter all the necessary fields";
else{
$sql = "INSERT INTO q_cat (cat_name, lang) VALUES ('$cat_name', '$lang_select')";
$result = mysql_query($sql);
echo "<strong>Category successfully added to the database...</strong>\n";
echo "onload=\"where='index.php'; setTimeout('document.location.href=where',2000);\"";
}

what is the problem and how can i find a good tutorial about using javascript in php???

Reply With Quote
  #2  
Old December 1st, 2002, 02:49 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Re: Not working if???

PHP Code:
include("../db_funcs/dbconnect.inc");


if(!
$cat_name || !$lang_select)
{    
echo 
"Please enter all the necessary fields";
}
else
{
    
$sql "INSERT INTO q_cat (cat_name, lang) VALUES ('$cat_name', '$lang_select')";
    
$result mysql_query($sql); 
    echo 
"<strong>Category successfully added to the database...</strong>\n"
    echo 
"onload=\"where='index.php'; setTimeout('document.location.href=where',2000);\"";



You missed out the opening and closing curly braces on the if statement.

Reply With Quote
  #3  
Old December 1st, 2002, 03:09 PM
cemlouis cemlouis is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 49 cemlouis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I opened for else and close for it but it is not necessary for if i think, i mean it is working without the line of

PHP Code:
echo "onload=\"where='index.php'; setTimeout('document.location.href=where',2000);\""


it is a javascript and i think i am writing it wrong...

Reply With Quote
  #4  
Old December 1st, 2002, 03:11 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
you dont need curley braces if you only have one line after

say

if()
//code here that would excute if above if statement is true

Reply With Quote
  #5  
Old December 2nd, 2002, 05:56 AM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Are you sure? I'd always used the curly braces religiously... how else would PHP know when to start executing the code and where to stop?

PHP Code:
if (condition)
{
do 
this;
}
else
{
Do 
this;


Reply With Quote
  #6  
Old December 6th, 2002, 01:53 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Kanu,

I, too, use braces for all my if statements, but you don't necessarily need them if you have single-lined IF statements. They are only required for multi-lined statements...
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Not working if???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway