cvs: phpdoc /en/faq databases.xml general.xml html.xml installation.xml languages.xml migration.xml migration4.xml using.xml

From: Date: Sun, 14 Oct 2001 11:55:30 +0000
Subject: cvs: phpdoc /en/faq databases.xml general.xml html.xml installation.xml languages.xml migration.xml migration4.xml using.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969337976@lists.php.net to get a copy of this message
goba Sun Oct 14 07:55:30 2001 EDT Modified files: /phpdoc/en/faq databases.xml general.xml html.xml installation.xml languages.xml migration.xml migration4.xml using.xml Log: Moving things around, some content were in the wrong place. Spreading the content of common.xml among several files

Index: phpdoc/en/faq/databases.xml diff -u phpdoc/en/faq/databases.xml:1.9 phpdoc/en/faq/databases.xml:1.10 --- phpdoc/en/faq/databases.xml:1.9 Sun Oct 14 06:26:19 2001 +++ phpdoc/en/faq/databases.xml Sun Oct 14 07:55:30 2001 @@ -1,8 +1,8 @@ <?xml encoding="iso-8859-1"?> -<!-- $Revision: 1.9 $ --> +<!-- $Revision: 1.10 $ --> <chapter id="faq.databases"> - <title>Connecting to databases</title> - <titleabbrev>Connecting to databases</titleabbrev> + <title>Database issues</title> + <titleabbrev>Database issues</titleabbrev> <para> This section holds common questions about relation between @@ -193,6 +193,38 @@ or recompile from the source rpm and remove the switch in the spec file that turns on the threaded client code. Either of these suggestions will fix this. Then recompile PHP with the new MySQL libs. + </para> + </answer> + </qandaentry> + + <qandaentry id="faq.databases.mysqlresource"> + <question> + <para> + Why do I get an error that looks something like this: + "Warning: 0 is not a MySQL result index in &lt;file&gt; + on line &lt;x&gt;" or "Warning: Supplied argument is not + a valid MySQL result resource in &lt;file&gt; on line &lt;x&gt;? + </para> + </question> + <answer> + <para> + You are trying to use a result identifier that is 0. The 0 indicates + that your query failed for some reason. You need to check for errors + after submitting a query and before you attempt to use the returned + result identifier. The proper way to do this is with code similar + to the following: + <programlisting> +$result = mysql_query("SELECT * FROM tables_priv"); +if (!$result) { + echo mysql_error(); + exit; +} + </programlisting> + or + <programlisting> +$result = mysql_query("SELECT * FROM tables_priv") + or die("Bad query: ".mysql_error()); + </programlisting> </para> </answer> </qandaentry> Index: phpdoc/en/faq/general.xml diff -u phpdoc/en/faq/general.xml:1.10 phpdoc/en/faq/general.xml:1.11 --- phpdoc/en/faq/general.xml:1.10 Fri Sep 21 18:47:31 2001 +++ phpdoc/en/faq/general.xml Sun Oct 14 07:55:30 2001 @@ -1,13 +1,13 @@ <?xml encoding="iso-8859-1"?> -<!-- $Revision: 1.10 $ --> +<!-- $Revision: 1.11 $ --> <chapter id="faq.general"> <title>General Information</title> <titleabbrev>General Information</titleabbrev> - <para> - This section holds the most general questions about PHP: - what it is and what it does. - </para> + <para> + This section holds the most general questions about PHP: + what it is and what it does. + </para> <qandaset> <qandaentry id="faq.general.what"> @@ -16,7 +16,7 @@ </question> <answer> <para> - From the <ulink url="&faqurl.php.manual;">manual</ulink>: + From the <link linkend="preface">preface of the manual</link>: </para> <para> PHP is an HTML-embedded scripting language. Much of @@ -34,7 +34,7 @@ <qandaentry id="faq.general.relation-versions"> <question> - <para> What is the relation between the versions ?</para> + <para>What is the relation between the versions?</para> </question> <answer> <para> @@ -97,6 +97,26 @@ Please see the <ulink url="&faqurl.zend.new;">What's new in PHP4 overview</ulink> for a detailed explanation of these features and more. + </para> + </answer> + </qandaentry> + + <qandaentry id="faq.general.bug"> + <question> + <para> + I think I found a bug! Who should I tell? + </para> + </question> + <answer> + <para> + You should go to the PHP Bug Database and make sure the bug + isn't a known bug. If you don't see it in the database, use + the reporting form to report the bug. It is important to use + the bug database instead of just sending an email to one of the + mailing lists because the bug will have a tracking number assigned + and it will then be possible for you to go back later and check + on the status of the bug. The bug database can be found at + <ulink url="&faqurl.php.bugs;">&faqurl.php.bugs;</ulink>. </para> </answer> </qandaentry> Index: phpdoc/en/faq/html.xml diff -u phpdoc/en/faq/html.xml:1.5 phpdoc/en/faq/html.xml:1.6 --- phpdoc/en/faq/html.xml:1.5 Sun Oct 14 06:41:34 2001 +++ phpdoc/en/faq/html.xml Sun Oct 14 07:55:30 2001 @@ -1,5 +1,5 @@ <?xml encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <chapter id="faq.html"> <title>PHP and HTML</title> <titleabbrev>PHP and HTML</titleabbrev> @@ -10,6 +10,35 @@ </para> <qandaset> + <qandaentry id="faq.html.form-image"> + <question> + <para> + I'm trying to use an &lt;input type="image"&gt; tag, but + the $foo.x and $foo.y variables aren't available. + Where are they? + </para> + </question> + <answer> + <para> + When submitting a form, it is possible to use an image instead of + the standard submit button with a tag like: + <programlisting> +<![CDATA[ +<input type="image" src="image.gif" name="foo"> +]]> + </programlisting> + When the user clicks somewhere on the image, the accompanying form + will be transmitted to the server with two additional variables: + foo.x and foo.y. + </para> + <para> + Because $foo.x and $foo.y are invalid variable names in PHP, they are + automagically converted to $foo_x and $foo_y. That is, the periods + are replaced with underscores. + </para> + </answer> + </qandaentry> + <qandaentry id="faq.html.arrays"> <question> <para>How do I create arrays in a HTML &lt;form&gt;?</para> @@ -60,6 +89,58 @@ </answer> </qandaentry> + <qandaentry id="faq.html.select-multiple"> + <question> + <para> + How do I get all the results from a select multiple HTML tag? + </para> + </question> + <answer> + <para> + The select multiple tag in an HTML construct allows users to + select multiple items from a list. These items are then passed + to the action handler for the form. The problem is that they + are all passed with the same widget name. ie. + <programlisting> +<![CDATA[ +<select name="var" multiple> +]]> + </programlisting> + Each selected option will arrive at the action handler as: + <programlisting> +var=option1 +var=option2 +var=option3 + </programlisting> + Each option will overwrite the contents of the previous + <varname>$var</varname> variable. The solution is to use + PHP's "array from form element" feature. The following + should be used: + <programlisting> +<![CDATA[ +<select name="var[]" multiple> +]]> + </programlisting> + This tells PHP to treat <varname>$var</varname> as an array and + each assignment of a value to var[] adds an item to the array. + The first item becomes <varname>$var[0]</varname>, the next + <varname>$var[1]</varname>, etc. The <function>count</function> + function can be used to determine how many options were selected, + and the <function>sort</function> function can be used to sort + the option array if necessary. + </para> + <para> + Note that if you are using JavaScript the <literal>[]</literal> + on the element name might cause you problems when you try to + refer to the element by name. Use it's numerical form element + id instead, or enclose the variable name in single quotes and + use that as the index to the elements array, for example: + <programlisting> +variable = documents.forms[0].elements['var[]']; + </programlisting> + </para> + </answer> + </qandaentry> </qandaset> </chapter> Index: phpdoc/en/faq/installation.xml diff -u phpdoc/en/faq/installation.xml:1.8 phpdoc/en/faq/installation.xml:1.9 --- phpdoc/en/faq/installation.xml:1.8 Sun Oct 14 05:16:30 2001 +++ phpdoc/en/faq/installation.xml Sun Oct 14 07:55:30 2001 @@ -1,5 +1,5 @@ <?xml encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <chapter id="faq.installation"> <title>Installation</title> <titleabbrev>Installation</titleabbrev> @@ -45,6 +45,81 @@ </answer> </qandaentry> + <qandaentry id="faq.installation.nodata"> + <question> + <para> + Unix: I installed PHP, but every time I load a document, I get the + message 'Document Contains No Data'! What's going on here? + </para> + </question> + <answer> + <para> + This probably means that PHP is having some sort of problem + and is core-dumping. Look in your server error log to see if + this is the case, and then try to reproduce the problem with + a small test case. If you know how to use 'gdb', it is very + helpful when you can provide a backtrace with your bug report + to help the developers pinpoint the problem. If you are using + PHP as an Apache module try something like: + <itemizedlist> + <listitem> + <para> + Stop your httpd processes + </para> + </listitem> + <listitem> + <para> + gdb httpd + </para> + </listitem> + <listitem> + <para> + Stop your httpd processes + </para> + </listitem> + <listitem> + <para> + &gt; run -X -f /path/to/httpd.conf + </para> + </listitem> + <listitem> + <para> + Then fetch the URL causing the problem with your browser + </para> + </listitem> + <listitem> + <para> + &gt; run -X -f /path/to/httpd.conf + </para> + </listitem> + <listitem> + <para> + If you are getting a core dump, gdb should inform you of this now + </para> + </listitem> + <listitem> + <para> + type: bt + </para> + </listitem> + <listitem> + <para> + You should include your backtrace in your bug report. This should be submitted to + <ulink url="&faqurl.php.bugs;">&faqurl.php.bugs;</ulink> + </para> + </listitem> + </itemizedlist> + </para> + <para> + If your script uses the regular expression functions + (<function>ereg</function> and friends), you should make sure + that you compiled PHP and Apache with the same regular + expression package. This should happen automatically with + PHP and Apache 1.3.x + </para> + </answer> + </qandaentry> + <qandaentry id="faq.installation.processing"> <question> <para> @@ -177,6 +252,24 @@ </answer> </qandaentry> + <qandaentry id="faq.installation.frontpage"> + <question> + <para> + Unix: I patched Apache with the FrontPage extensions patch, and + suddenly PHP stopped working. Is PHP incompatible with the + Apache FrontPage extensions? + </para> + </question> + <answer> + <para> + No, PHP works fine with the FrontPage extensions. The problem + is that the FrontPage patch modifies several Apache structures, + that PHP relies on. Recompiling PHP (using 'make clean ; make') + after the FP patch is applied would solve the problem. + </para> + </answer> + </qandaentry> + <qandaentry id="faq.installation.blankscreen"> <question> <para> @@ -277,6 +370,26 @@ </itemizedlist> </answer> </qandaentry> + + <qandaentry id="faq.install.phpandiis"> + <question> + <para> + Windows: I've followed all the instructions, but still can't + get PHP and IIS to work together! + </para> + </question> + <answer> + <para> + Make sure any user who needs to run a PHP script has the rights + to run <filename>php.exe</filename>! IIS uses an anonymous user + which is added at the time IIS is installed. This user needs + rights to <filename>php.exe</filename>. Also, any authenticated + user will also need rights to execute <filename>php.exe</filename>. + And for IIS4 you need to tell it that PHP is a script engine. + </para> + </answer> + </qandaentry> + </qandaset> </chapter> Index: phpdoc/en/faq/languages.xml diff -u phpdoc/en/faq/languages.xml:1.6 phpdoc/en/faq/languages.xml:1.7 --- phpdoc/en/faq/languages.xml:1.6 Fri Sep 21 18:47:31 2001 +++ phpdoc/en/faq/languages.xml Sun Oct 14 07:55:30 2001 @@ -1,13 +1,13 @@ <?xml encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <chapter id="faq.languages"> <title>PHP and other languages</title> <titleabbrev>PHP and other languages</titleabbrev> - <para> - PHP is the best language for Webbing, but what about - other languages? - </para> + <para> + PHP is the best language for web programing, + but what about other languages? + </para> <qandaset> <qandaentry id="faq.languages.asp"> @@ -17,23 +17,26 @@ <answer> <para> ASP is not really a language in itself, it's an acronym for Active - Server Pages, the actual language used to program ASP with is a - script version of Visual Basic. The biggest drawback of ASP is that + Server Pages, the actual language used to program ASP with is Visual + Basic Script or JScript. The biggest drawback of ASP is that it's a proprietary system that is natively used only on Microsoft Internet Information Server (IIS). This limits it's availability to Win32 based servers. There are a couple of projects in the works - that allows ASP to run in other environments and webservers; + that allows ASP to run in other environments and webservers: <ulink url="&faqurl.instantasp;">InstantASP</ulink> from <ulink url="&faqurl.halcyon;">Halcyon</ulink> (commercial), <ulink url="&faqurl.chilisoft.asp;">Chili!Soft ASP</ulink> from <ulink url="&faqurl.chilisoft;">Chili!Soft</ulink> - (commercial) and <ulink url="&faqurl.openasp;">OpenASP from ActiveScripting.org</ulink> - (free). ASP is said to be a slower + (commercial) and <ulink url="&faqurl.openasp;">OpenASP from + ActiveScripting.org</ulink> (free). ASP is said to be a slower and more cumbersome language than PHP, less stable as well. Some of - the pros of ASP is that since it uses VBScript it's relatively easy - to pick up the language if you're already know how to program in - Visual Basic. ASP support is also enabled by default in the IIS - server making it easy to get up and running. + the pros of ASP is that since it primarily uses VBScript it's + relatively easy to pick up the language if you're already know + how to program in Visual Basic. ASP support is also enabled by + default in the IIS server making it easy to get up and running. + The components built in ASP are really limited, so if you + need to use "advanced" features like interacting with FTP servers, + you need to buy additional components. </para> </answer> </qandaentry> @@ -44,8 +47,8 @@ </question> <answer> <para> - Yes, <ulink url="&faqurl.asp2php;">asp2php</ulink> is the one most often - referred to. + Yes, <ulink url="&faqurl.asp2php;">asp2php</ulink> is + the one most often referred to. </para> </answer> </qandaentry> @@ -60,14 +63,15 @@ programming tasks and trying out new ideas. PHP is generally referred to as more stable and less resource intensive as well. Cold Fusion has better error handling, database abstraction and date parsing - although database abstraction is being addressed in PHP 4. Another + although database abstraction is addressed in PHP 4. Another thing that is listed as one of Cold Fusion's strengths is its excellent search engine, but it has been mentioned that a search engine is not something that should be included in a web scripting language. PHP runs on almost every platform there is; Cold Fusion is only available - on Win32, Solaris, Linux and HP/UX. Cold Fusion has a better IDE + on Win32, Solaris, Linux and HP/UX. Cold Fusion has a good IDE and is generally easier to get started with, whereas PHP initially - requires more programming knowledge. + requires more programming knowledge. Cold Fusion is designed with + non-programmers in mind, while PHP is focused on programmers. </para> <para> A great summary by Michael J Sheldon on this topic has @@ -88,9 +92,9 @@ because of this get very complicated. The flexibility / complexity of Perl makes it easier to write code that another author / coder has a hard time reading. PHP has a less confusing and stricter format - without losing flexibility. PHP is easier to integrate into existing + without losing flexibility. PHP is easier to integrate into existing HTML than Perl. PHP has pretty much all the 'good' functionality of - Perl; constructs, syntax and so on, without making it as complicated + Perl: constructs, syntax and so on, without making it as complicated as Perl can be. Perl is a very tried and true language, it's been around since the late eighties, but PHP is maturing very quickly. </para> Index: phpdoc/en/faq/migration.xml diff -u phpdoc/en/faq/migration.xml:1.6 phpdoc/en/faq/migration.xml:1.7 --- phpdoc/en/faq/migration.xml:1.6 Fri Sep 21 18:47:31 2001 +++ phpdoc/en/faq/migration.xml Sun Oct 14 07:55:30 2001 @@ -1,26 +1,32 @@ <?xml encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <chapter id="faq.migration"> <title>Migrating from PHP 2 to PHP 3</title> <titleabbrev>Migrating from PHP 2 to PHP 3</titleabbrev> - <para> - PHP has already a long history behind him : - Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP/Zend 4.0. - </para> + <para> + PHP has already a long history behind him: + Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP 4.0. + </para> <qandaset> <qandaentry id="faq.migrating.phpfi"> <question> <para> - Migrating from PHP2 to PHP3? + Migrating from PHP 2 to PHP 3? </para> </question> <answer> <para> PHP/FI 2.0 is no longer supported. Please see - <link linkend="migration">the manual</link> for - information about migration from PHP/FI 2.0. + <link linkend="migration">appropriate manual + section</link> for information about migration + from PHP/FI 2.0. + </para> + <para> + If you are still working with PHP 2, we + <emphasis>strongly</emphasis> recommend you + to upgrade straight to PHP 4. </para> </answer> </qandaentry> Index: phpdoc/en/faq/migration4.xml diff -u phpdoc/en/faq/migration4.xml:1.5 phpdoc/en/faq/migration4.xml:1.6 --- phpdoc/en/faq/migration4.xml:1.5 Fri Sep 21 18:47:31 2001 +++ phpdoc/en/faq/migration4.xml Sun Oct 14 07:55:30 2001 @@ -1,19 +1,19 @@ <?xml encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <chapter id="faq.migration4"> <title>Migrating from PHP 3 to PHP 4</title> <titleabbrev>Migrating from PHP 3 to PHP 4</titleabbrev> - <para> - PHP has already a long history behind him : - Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP/Zend 4.0. - </para> + <para> + PHP has already a long history behind him : + Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP 4.0. + </para> <qandaset> <qandaentry id="faq.migration4.php34"> <question> <para> - Migrating from PHP3 to PHP4 + Migrating from PHP3 to PHP4 </para> </question> <answer> @@ -23,13 +23,17 @@ process. If you're really unsure about compatibility you should install PHP 4 in a test environment and run your scripts there. </para> + <para> + Also see the <link linkend="migration4">appropriate migration + appendix</link> of this manual. + </para> </answer> </qandaentry> <qandaentry id="faq.migration4.incompatible"> <question> <para> - Incompatibles functions? + Incompatible functions? </para> </question> <answer> Index: phpdoc/en/faq/using.xml diff -u phpdoc/en/faq/using.xml:1.8 phpdoc/en/faq/using.xml:1.9 --- phpdoc/en/faq/using.xml:1.8 Wed Oct 3 15:16:08 2001 +++ phpdoc/en/faq/using.xml Sun Oct 14 07:55:30 2001 @@ -1,13 +1,13 @@ <?xml encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <chapter id="faq.using"> <title>Using PHP</title> <titleabbrev>Using PHP</titleabbrev> - <para> - This section gathers most common errors that occur at - build time. - </para> + <para> + This section gathers most common errors you can + face, while writing PHP scripts. + </para> <qandaset> <qandaentry id="faq.using.anyform"> @@ -19,19 +19,20 @@ </question> <answer> <para> - Make sure that the track_vars feature is - enabled in your php3.ini file. If you compiled PHP with - &quot;--enable-track-vars&quot; it will be on by default. - Alternatively you can enable it at run-time on a per-script - basis by putting &lt;?php_track_vars?&gt; at the top of your file. - When track_vars is on, it creates three associative arrays. - $HTTP_GET_VARS, $HTTP_POST_VARS and $HTTP_COOKIE_VARS. So, to - write a generic script to handle POST method variables you would + Make sure that the <link linkend="ini.track-vars">track_vars</link> + feature is enabled in your <filename>php.ini</filename> + file. Since PHP 4.0.3, this feature is always on. When + <literal>track_vars</literal> is on, it creates some + associative arrays, the most important here is: + <literal>$HTTP_POST_VARS</literal>. So, to write a generic + script to handle POST method variables you would need something similar to the following: <programlisting> - while (list($var, $value) = each($HTTP_POST_VARS)) { - echo "$var = $value&lt;br&gt;\n"; - } +<![CDATA[ +foreach ($HTTP_POST_VARS as $var => $value) { + echo "$var = $value<br>\n"; +} +]]> </programlisting> </para> </answer> @@ -47,8 +48,8 @@ </question> <answer> <para> - First off, take a look at the <function>addslashes()</function> - function. It will do exactly what you want. You should also have + First off, take a look at the <function>addslashes</function> + function. It will do exactly what you want. You should also have a look at the <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> directive in your <filename>php.ini</filename> file. </para> @@ -61,11 +62,12 @@ When I do the following, the output is printed in the wrong order: <programlisting> - function myfunc($argument) { - echo $argument + 10; - } - $variable = 10; - echo "myfunc($variable) = " . myfunc($variable); +function myfunc($argument) +{ + echo $argument + 10; +} +$variable = 10; +echo "myfunc($variable) = " . myfunc($variable); </programlisting> what's going on? </para> @@ -84,19 +86,24 @@ <question> <para> Hey, what happened to my newlines? - <programlisting> -&lt;PRE&gt; - 1 &lt;?echo $result[1];?&gt; - 2 &lt;?echo $result[2];?&gt; - </programlisting> + <programlisting> +<![CDATA[ +<pre> +<?php echo "This should be the first line."; ?> +<?php echo "This should show up after the new line above."; ?> +</pre> +]]> + </programlisting> </para> </question> <answer> <para> In PHP, the ending for a block of code is either "?&gt;" or - "?&gt;\n" (where \n means a newline). This means that you need to - insert an extra newline after each block of PHP code in the above - example. + "?&gt;\n" (where \n means a newline). So in the example above, + the echoed sentences will be on one line, because PHP ommits + the newlines after the block ending. This means that you need to + insert an extra newline after each block of PHP code to make + it print out one newline. </para> <para> Why does PHP do this? Because when formatting normal HTML, this @@ -117,14 +124,16 @@ <answer> <para> The <function>getallheaders</function> function will do this if - you are running PHP as a module. So, the following bit of code - will show you all the request headers: - <programlisting> - $headers = getallheaders(); - for(reset($headers); $key = key($headers); next($headers)) { - echo "headers[$key] = ".$headers[$key]."&lt;br&gt;\n"; - } - </programlisting> + you are running PHP as an Apache module. So, the following bit + of code will show you all the request headers: + <programlisting> +<![CDATA[ +$headers = getallheaders(); +foreach ($headers as $name => $content) { + echo "headers[$name] = $content<br>\n"; +} +]]> + </programlisting> </para> </answer> </qandaentry> @@ -137,34 +146,15 @@ </question> <answer> <para> - The security model of IIS is at fault here. This is a problem - common to all CGI programs running under IIS. A workaround is - to create a plain HTML file (not parsed by php) as the entry page - into an authenticated directory. Then use a META tag to redirect - to the PHP page, or have a link to the PHP page. PHP will - then recognize the authentication correctly. When the ISAPI - module is ready, this will no longer be a problem. This should - not effect other NT web servers. For more information, see: - <ulink url="&faqurl.iis;">&faqurl.iis;</ulink>. - </para> - </answer> - </qandaentry> - - <qandaentry id="faq.using.PHP-IIS"> - <question> - <para> - I've followed all the instructions, but still can't - get PHP and IIS to work together! - </para> - </question> - <answer> - <para> - Make sure any user who needs to run a PHP script has the rights - to run <filename>php.exe</filename>! IIS uses an anonymous user which is added at the - time IIS is installed. This user needs rights to <filename>php.exe</filename>. - Also, any authenticated user will also need rights to execute - <filename>php.exe</filename>. And for IIS4 you need to tell it - that PHP is a script engine. + The security model of IIS is at fault here. This is a problem + common to all CGI programs running under IIS. A workaround is + to create a plain HTML file (not parsed by PHP) as the entry page + into an authenticated directory. Then use a META tag to redirect + to the PHP page, or have a link to the PHP page. PHP will + then recognize the authentication correctly. With the ISAPI + module, this is not a problem. This should not effect other + NT web servers. For more information, see: + <ulink url="&faqurl.iis;">&faqurl.iis;</ulink>. </para> </answer> </qandaentry> @@ -179,19 +169,19 @@ </question> <answer> <para> - Very good question! ;) This is a tricky little issue and it has come up - twice in the past month as of this writing. Both times I ended up + Very good question! ;) This is a tricky little issue and it has come up + twice in the past month as of this writing. Both times I ended up spending a good 20 minutes trying to figure out what the heck was going - on. The answer is that both IE and Lynx ignore any NULs - (<literal>\0</literal>) in the HTML stream. Netscape does not. + on. The answer is that both IE and Lynx ignore any NULs + (<literal>\0</literal>) in the HTML stream. Netscape does not. The best way to check for this is to compile the command-line version of PHP (also known as the CGI version) and run your script from the command line and pipe it through 'od -c' and look for any - <literal>\0</literal> characters. (If you are on Windows you need to + <literal>\0</literal> characters. (If you are on Windows you need to find an editor or some other program that lets you look at binary files) When Netscape sees a NUL in a file it will typically not output - anything else on that line whereas both IE and Lynx will. If this - issue has bitten you, congratulations! You are not alone. + anything else on that line whereas both IE and Lynx will. If this + issue has bitten you, congratulations! You are not alone. </para> </answer> </qandaentry> @@ -205,11 +195,11 @@ </question> <answer> <para> - You need to turn off the short tags by setting short_tags to 0 in your - <filename>php.ini</filename> file, or by using the php3_short_tags Apache - directive. (You could even use a &lt;File&gt; section to do this - selectively.) You can also disable and re-enable the short tags - in your script using the short_tags() function. + You need to turn off the short tags by setting + <link linkend="ini.short-open-tag">short_tags</link> to 0 in your + <filename>php.ini</filename> file, or by using the appropriate + Apache directive. You could even use a &lt;File&gt; section to + do this selectively. </para> </answer> </qandaentry> @@ -217,18 +207,19 @@ <qandaentry id="faq.using.editor"> <question> <para> - How can I use PHP with FrontPage or Dreamweaver or some - other HTML editor that insists on moving my code around? + How can I use PHP with FrontPage or some other HTML editor + that insists on moving my code around? </para> </question> <answer> <para> One of the easiest things to do is to enable using ASP tags in your PHP code. This allows you to use the ASP-style &lt;% and %&gt; code - delimiters. Most of the popular HTML editors handle those more + delimiters. Some of the popular HTML editors handle those more intelligently (for now). To enable the ASP-style tags, you need - to set the asp_tags <filename>php.ini</filename> variable, or use the - <link linkend="ini.asp-tags">asp_tags</link> Apache directive. + to set the <link linkend="ini.asp-tags">asp_tags</link> + <filename>php.ini</filename> variable, or use the + appropriate Apache directive. </para> </answer> </qandaentry> @@ -242,120 +233,34 @@ </question> <answer> <para> - The best way is to stick a &lt;?phpinfo()?&gt; tag on a page and - load it up. This will show you all sorts of information about your - PHP setup, including a list of both environment variables and also - special variables set by your web server. This list can't really be - documented in the PHP documentation because it will change from one - server to another. - </para> - </answer> - </qandaentry> - - <qandaentry id="faq.using.mysql"> - <question> - <para> - Why do I get an error that looks something like this: - "Warning: 0 is not a MySQL result index in &lt;file&gt; - on line &lt;x&gt;" or "Warning: Supplied argument is not - a valid MySQL result resource in &lt;file&gt; on line &lt;x&gt;? - </para> - </question> - <answer> - <para> - You are trying to use a result identifier that is 0. The 0 indicates - that your query failed for some reason. You need to check for errors - after submitting a query and before you attempt to use the returned - result identifier. The proper way to do this is with code similar - to the following: - <programlisting> - $result = mysql_query("select * from tables_priv"); - if(!$result) { - echo mysql_error(); - exit; - } - </programlisting> - or - <programlisting> - $result = mysql_query("select * from tables_priv") - or die("Bad query: ".mysql_error()); - </programlisting> + The best way is to stick a <literal>&lt;?php phpinfo(); ?&gt;</literal> + part on a page and load it up. This will show you all sorts of + information about your PHP setup, including a list of both + environment variables and also special variables set by your + web server. This list can't really be documented in the PHP + documentation because it will change from one server to another. </para> </answer> </qandaentry> - <qandaentry id="faq.using.form-image"> + <qandaentry id="faq.using.cgi-vars"> <question> <para> - I'm trying to use an &lt;input type="image"&gt; tag, but - the $foo.x and $foo.y variables aren't available. - Where are they? + I'm trying to access one of the standard CGI + variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined + function, and it can't seem to find it. What's wrong? </para> </question> <answer> <para> - When submitting a form, it is possible to use an image instead of - the standard submit button with a tag like: - <programlisting> -&lt;input type="image" SRC="image.gif" NAME="foo"&gt; - </programlisting> - When the user clicks somewhere on the image, the accompanying form - will be transmitted to the server with two additional variables: - foo.x and foo.y. - </para> - <para> - Because $foo.x and $foo.y are invalid variable names in PHP, they are - automagically converted to $foo_x and $foo_y. That is, the periods - are replaced with underscores. + Environment variables are normal global variables, so you must + either declare them as global variables in your function (by using + "<literal>global $DOCUMENT_ROOT;</literal>", for example) or by using + the global variable array (ie, "<literal>$GLOBALS["DOCUMENT_ROOT"]</literal>". </para> </answer> </qandaentry> - <qandaentry id="faq.using.select-multiple"> - <question> - <para> - How do I get all the results from a SELECT MULTIPLE HTML tag? - </para> - </question> - <answer> - <para> - The SELECT MULTIPLE tag in an HTML construct allows users to select multiple - items from a list. These items are then passed to the action handler for the - form. The problem is that they are all passed with the same widget name. ie. - <programlisting> - &lt;SELECT NAME="var" MULTIPLE&gt; - </programlisting> - Each selected option will arrive at the action handler as: - <programlisting> - var=option1 - var=option2 - var=option3 - </programlisting> - Each option will overwrite the contents of the previous $var variable. The - solution is to use PHP's - non-indexed array feature. The following should be used: - <programlisting> -&lt;SELECT NAME="var[]" MULTIPLE&gt; - </programlisting> - This tells PHP to treat <varname>var</varname> as an array and each assignment of a - value to var[] adds an item to the array. The first item becomes - <varname>$var[0]</varname>, the next <varname>$var[1]</varname>, etc. - The <function>count</function> function can be used to determine how - many options were selected, and the <function>sort</function> function can be - used to sort the option array if necessary. - </para> - <para> - Note that if you are using JavaScript the <literal>[]</literal> on the element name - might cause you problems when you try to refer to the element by name. - Use it's numerical form element id instead, or enclose the - variable name in single quotes and use that as the index to the - elements array, for example: - <programlisting> -variable = documents.forms[0].elements['var[]']; - </programlisting> - </para> - </answer> - </qandaentry> </qandaset> </chapter>
« previous php.doc (#969337976) next »