Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2004, 02:54 AM
Authorized User
 
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default expecting `T_STRING'

i have this query...

Code:
$query2=query("SELECT * FROM tempKomponen WHERE komponen = '$senarai["alat"]' ORDER BY komponen", $link, __LINE__, __FILE__);
$periksa = mysql_fetch_array($query2, MYSQL_ASSOC);


and then i get this error:
Code:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in g:\programming\phpdev\www\mmis\analysis\outsnapkomponen.php on line 114
line 114 refers to the
Code:
$periksa = mysql_fetch_array($query2, MYSQL_ASSOC);



how to fix that?
even i delete the line 114,the error still point me at the line 114...

 
Old January 29th, 2004, 04:04 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

$query2=query("SELECT * FROM tempKomponen WHERE komponen = '{$senarai["alat"]}' ORDER BY komponen", $link, __LINE__, __FILE__);
$periksa = mysql_fetch_array($query2, MYSQL_ASSOC);

The error was due to the use of quotes in your array. Use curly syntax, as I have above.
The program returns the next line because it got confused!

Have a look at the PHP manual page on strings which explains the various variable parsing mechanisms that PHP uses and what to do to get PHP to recognize variables from within string context. One of those methods being curly syntax.
http://www.php.net/manual/en/language.types.string.php

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old January 29th, 2004, 04:07 AM
Authorized User
 
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ooopss..i just want to delete my topic here because i just remembered about the curly text...anyway thanc quasedilla5!!!

 
Old January 29th, 2004, 04:12 AM
Authorized User
 
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmmm...but another common error appears...the famous PARSE error!!!
Code:
$c->setPlotArea(70, 50, 320, 150, 0xffffff, 0xffffff, 0xc0c0c0, 0xc0c0c0);
$title = $c->addTitle("Revenue for Last 10 Years", "timesbi.ttf");
the parse error point at the second line..how to fix that??
i already put the semicolon there?
so what else parse error means?

 
Old January 29th, 2004, 04:38 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

$c->setPlotArea(70, 50, 320, 150, '0xffffff', '0xffffff', '0xc0c0c0', '0xc0c0c0');

'0xffffff' is a string!

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old January 29th, 2004, 04:47 AM
Authorized User
 
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

its not working....
FYI,this code i downloaded from a website...
and it suppose to be working because it has been downloaded and used by many people..
how to fix that???

 
Old January 29th, 2004, 07:38 AM
Authorized User
 
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

errrmmm....it ok...i fixed that..
its a silly mistake actually...
but after that,this error appears:
Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in g:\programming\phpdev\www\mmis\analysis\outsnapkomponen.php on line 133
and the code is:
Code:
$nilai=$periksa["jumlah"]+1;
$query4=query("UPDATE tempkomponen SET jumlah = '$nilai'  WHERE komponen ='{$senarai["alat"]}'", $link, __LINE__, __FILE__);
$komponen2 = mysql_fetch_array($query4, MYSQL_ASSOC);
    } 
$bil=$bil+1;
and on the line 133 theres only a curly bracket "}"
actually what "supplied argument is not a valid MySQL result resource" means??
 
Old January 29th, 2004, 07:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"Not a valid mysql resource" means that MySQL could not execute your query. Since you're using a wrapper function called query() which accepts the current filename and line number (__FILE__ and __LINE__) as arguments, I would guess that that function would output the error somewhere.


As a completely unrelated and helpful suggestion, you should really get into the habit of using spaces to separate your variables, operators, etc... It makes things much more readable.

Consider your code:

Code:
$nilai=$periksa["jumlah"]+1;
$query4=query("UPDATE tempkomponen SET jumlah = '$nilai'  WHERE komponen ='{$senarai["alat"]}'", $link, __LINE__, __FILE__);
$komponen2 = mysql_fetch_array($query4, MYSQL_ASSOC);
    } 
$bil=$bil+1;
And consider this rewriting:
Code:
    $nilai  = $periksa["jumlah"] + 1;

    $query = "UPDATE tempkomponen "
           . "   SET jumlah   = '$nilai' "
           . " WHERE komponen = '{$senarai["alat"]}'";

    $result    = query($query, $link, __LINE__, __FILE__);
    $komponen2 = mysql_fetch_array($result, MYSQL_ASSOC);
}

++$bil;

Your curly braces are there to provide block-level nesting. It looks a lot more intuitive if you use whitespace and indentation to organize your nesting.


Take care,

Nik
http://www.bigaction.org/
 
Old January 29th, 2004, 07:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh yeah, and Rich -- 0xffffffff is NOT a string, it's a number. The 0x tells the PHP parser that the number is going to be represented using hex digits.

  http://www.php.net/types.integer


Take care,

Nik
http://www.bigaction.org/
 
Old January 29th, 2004, 09:58 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Oops. Sorry about that. Well it smelled like a string to me!

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
PHP Parse error: parse error, unexpected T_STRING geminient PHP How-To 4 August 18th, 2007 02:27 AM
Unexpected : t_string, t_variable, t_num_string scifo PHP Databases 13 November 15th, 2004 05:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.