 |
| 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
|
|
|
|

January 29th, 2004, 02:54 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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...
|
|

January 29th, 2004, 04:04 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
$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
:::::::::::::::::::::::::::::::::
|
|

January 29th, 2004, 04:07 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ooopss..i just want to delete my topic here because i just remembered about the curly text...anyway thanc quasedilla5!!!
|
|

January 29th, 2004, 04:12 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

January 29th, 2004, 04:38 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
$c->setPlotArea(70, 50, 320, 150, '0xffffff', '0xffffff', '0xc0c0c0', '0xc0c0c0');
'0xffffff' is a string!
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
|
|

January 29th, 2004, 04:47 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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???
|
|

January 29th, 2004, 07:38 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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??
|
|

January 29th, 2004, 07:31 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
"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/
|
|

January 29th, 2004, 07:33 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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/
|
|

January 29th, 2004, 09:58 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
Oops. Sorry about that. Well it smelled like a string to me!
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
|
|
 |