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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 25th, 2002, 08:05 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Question if statment not working?

I have the following if statement...

PHP Code:
if (!$ModCode) || !$Title || !$Lecturer || !Week || !$Topics)
    {
    echo 
"You have not completed the form correctly,
    Please go back and try again."
;
    exit;
    } 


But I get the following error...

Parse error: parse error, unexpected T_BOOLEAN_OR in C:\FoxServ\www\grabfile.php on line 19

And this is from a script copied straight out of a text book!

Any ideas as to why I am getting this error?

Your help is always appreciated!

Gee

Reply With Quote
  #2  
Old November 25th, 2002, 08:14 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
PHP Code:
if ( ( !$ModCode ) || ( !$Title ) || ( !$Lecturer ) || ( !Week ) || ( !$Topics ) ) 
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old November 25th, 2002, 08:18 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
PHP Code:
if (!$ModCode) || !$Title || !$Lecturer || !Week || !$Topics)
    {
    echo 
"You have not completed the form correctly,
    Please go back and try again."
;
    exit;
    } 


Just to let you know the problem was in your if statement

if (!$ModCode)

is the first part of the code, you closed off your if statement too early, hence the problems occuring.

Reply With Quote
  #4  
Old November 25th, 2002, 08:29 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
ThnX,

That solved the problem...

however, now the script always returns "you have not completed the form properly, go back and try again". Even though I make sure I enter the correct data into each field on the form.

I had this same problem with another tutorial I was working on, saying I hadn't filled in all the form properly when I made sure I did.

Any Ideas?

I keep running into brick walls here!


Gee

Reply With Quote
  #5  
Old November 26th, 2002, 05:34 AM
Silveria Silveria is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 7 Silveria User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Have you checked that the name of the forms are the same as the name of the variables you are checking in your if-statement?

Maybe a dumb question but hey

Reply With Quote
  #6  
Old November 26th, 2002, 11:43 AM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
PHP Code:
if (!$_POST['ModCode'] || !$_POST['Title'] || !$_POST['Lecturer'] || !$_POST['Week'] || !$_POST['Topics'])
    {
    echo 
"You have not completed the form correctly,
    Please go back and try again."
;
    exit;
    } 


make sure you have the exact variable names, and try to use the superglobals

Reply With Quote
  #7  
Old November 26th, 2002, 12:43 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hey ThnX Crazytrain81,

And all u other guys for helping me out. I am finally starting to get the hang of this language!!!

One thing however, is this business with naming variables,

$varname;
global $varname;
$_POST[varname];

and you mention superglobals?

my text book doesnt have much on this subject and I find the online manual doesnt explain things very well.

Do you know of any tutorials out there that address this subject or maybe you could tell me in plain n simple terms (haha) exactly how I should be declaring each of my variables.

All the examples in my book just declare them as $varname;

Gee

Reply With Quote
  #8  
Old November 26th, 2002, 12:56 PM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
In the variables section of the php manual at php.net, you'll see a section for 'predefined' variables. It goes in depth into the superglobals, $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_SESSION, and the scarcely used $_REQUEST.

A very brief explanation of these...

first of all, they're intended to replace $HTTP_X_VARS arrays. The main purpose is an easy, always-accessible method to access variables that are 'beyond the scope' of your script. eg, $_REQUEST, $_GET, $_POST.. they're all part of the http request. $_SERVER is based on http data your server has about the requesting host. $_ENV contains server environment information.

I'd just check that part of the manual.. hope this helped =P

Reply With Quote
  #9  
Old November 26th, 2002, 01:18 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hey Crazytrain,

I am gonna study that manual and make sure Ive got the information sunk into my brain!

Still that if statement doesnt work.

I have attached my form, script and database file if anyone wants to take a look at it.

I WOULD BE VERY GRATEFUL

Gee
Attached Files
File Type: zip help_pleeze.zip (2.6 KB, 204 views)

Reply With Quote
  #10  
Old November 26th, 2002, 04:02 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hey peoples

I got the if statement working finally, using the $_POST['var'],

ThnX for that!!!

haha - but its not over yet...

ok - all my code now seems to run fine apart from this...
PHP Code:
 mysql_select_db("projectg");
    
$query "insert into lecfiles VALUES
                (0, modCode, modTitle, lecturer, week, topics)"
;
    
$result mysql_query($query);

    if (
$result)
        echo 
mysql_affected_rows()." Data inserted into Database."


the problem is, only the first value 0, goes into my table no problem, I use this as a unique file id (It works correctly, giving a new id each time a record is inserted) . All the rest of the values do not insert into the table (when I look at the table in mysql these records contain NULL values).

Is this my bad syntax again? Ive checked n checked n changed it but still ziltch.

Massive respect if you can put this 1 to bed!!!

Gee

Reply With Quote
  #11  
Old November 26th, 2002, 04:33 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
Gee,

You should put your string variables within quotes when placing them in an SQL statement. Also, I'm not sure if they're variables or not, but you should be using your variable values.

PHP Code:
 mysql_select_db("projectg");
    
$query "insert into lecfiles VALUES
                (0, '$modCode', '$modTitle', '$lecturer', '$week', '$topics')"
;
    
$result mysql_query($query);

    if (
$result)
        echo 
mysql_affected_rows()." Data inserted into Database."


Hope it helps!
__________________
____________________________________________
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
  #12  
Old November 26th, 2002, 04:47 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Frankieshakes,

Yes they are variables recieved from a user form.

But your method unfortunatly still doesn't work for me.

Any other ides?

ThnX

Gee

Reply With Quote
  #13  
Old November 26th, 2002, 05:08 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
PHP Code:
 mysql_select_db("projectg");
    
$query "insert into lecfiles VALUES
                (0, '{$_POST['modCode']}', '{$_POST['modTitle']}', '{$_POST['lecturer']}', '{$_POST['week', '{$_POST['topics']}')"
;
    $result = mysql_query($query);

    if ($result)
        echo mysql_affected_rows().
" Data inserted into Database."


When anything is submitted via a form you should always use $_POST[]

In this cause, because $_POST is actually an array, you must encase the array $_POST[] in {}

Reply With Quote
  #14  
Old November 26th, 2002, 06:06 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
ThanX Ben and everyone else,

My script is working perfectly now!



Is this the normal way of handling such variables or have I taken a longer way round than most would? (Works a treat though!).

What makes me say this is just because there is an awful lot of syntax needed for each variable.

'{$_POST['modCode']}',


Gee

Reply With Quote
Reply

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


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