Make PHP Beginners Headache 14 Questions Big Summary _php skill

Source: Internet
Author: User
Tags flock mysql query php error urlencode win32
1, cannot pass the variable between the page


Get,post,session the automatic global variable is turned off in the latest PHP version, so the submitted variable from the previous page is to be obtained using $_get[' foo '],$_post[' foo '],$_session[' foo '. Of course, you can also modify the automatic global variable to open (php.ini changed to Register_globals = ON), and it is better to force yourself to be familiar with the new wording, considering compatibility.


2, Win32 under Apache2 The Get method to pass Chinese parameters will be wrong
test.php?a= Hello &b= You


Passing parameters can cause an internal error


Solution: "Test.php?a=". UrlEncode (Hello). " &b= ". UrlEncode (you are also good)


......


3, Win32 under the session does not work properly


php.ini default Session.save_path =/tmp


This is obviously a Linux configuration, Win32 under the PHP cannot read and write session file causes session not to use


Change it to an absolute path, such as Session.save_path = C:\Windows\Temp


4. Display error message


When PHP.ini's display_errors = on and error_reporting = E_all, all errors and prompts are displayed, and it is best to turn on the error when debugging, if you use the previous PHP error message is mostly about undefined variables. Variables are prompted before they are assigned, and the solution is to detect or mask them.


For example, $foo can be displayed, if (Isset ($foo)) echo $foo or echo @ $foo


5, Win32 under Mail () can not send e-mail


Under Linux configured SendMail can be sent, under Win32 need to invoke the SMTP server to send e-mail, modify the php.ini SMTP = IP//ip is without authentication function of the SMTP server (hard to find online), The best solution for PHP to send mail is to send it directly to the other email server without forwarding the server.


6, the first installed MySQL if you do not set a password, you should use


Update Mysql.user set password= "YourPassword" where user= "root"


Modify password


7, header already sent
This error usually occurs when you use the header, he may be several reasons: 1, you are Pring or Echo 2 before using header. You have a blank line 3 in front of your current file. You may include a file with a blank line at the end of the file or an error in the output.


8. No change after php.ini change


Restart the Web server, such as Iis,apache, and so on before applying the latest settings


9, PHP installed on the 2003 above (ISAPI installation method I implore the expert advice)


PHP4 's php4isapi.dll seems to be in conflict with 2003 and can only be installed in CGI mode:


Step one, first www.php.net under an installation process


10, sometimes the SQL statement does not work, the database operation failed


The easiest way to debug it, Echo's SQL, is to see if the value of the variable can be obtained.


11, include and require the difference


There is not much difference between the two, if the file to include does not exist, include prompts notice, and then proceed to execute the following statement, require prompt for fatal error and exit, as I have tested, Win32 platform under which they are first included after execution, So it's best not to have include or require statements in the included files, which can cause directory clutter. Maybe *nux under different circumstances, not yet tested.


If a file does not want to be included multiple times, you can use include_once or require_once## read to write document data:


Copy Code code as follows:

function R ($file _name) {
$filenum = @fopen ($file _name, "R");
@flock ($filenum, lock_sh);
$file _data= @fread ($filenum, FileSize ($file _name));
@fclose ($filenum);
return $file _data;
}
function W ($file _name, $data, $method = "W") {
$filenum = @fopen ($file _name, $method);
Flock ($filenum, LOCK_EX);
$file _data=fwrite ($filenum, $data);
Fclose ($filenum);
return $file _data;
}



12, the difference between isset () and empty ()


Both are used for test variables.


But Isset () is the test whether the variable is assigned, and empty () is to test whether a variable that has already been assigned is empty. If a variable is not assigned to the reference in PHP is allowed, but there will be a notice hint. If a variable is null, $foo = "" or $foo=0 or $foo =false, then empty ($foo) returns True, Isset ($foo) returns True, which means that the null value does not unregister a variable.


To unregister a variable, you can use either unset ($foo) or $foo=null.


13, the MySQL query statement contains a keyword


PHP query MySQL, sometimes MySQL table name or column name will have keywords. There will be errors in the query. For example, the table name is Order and the query can be faulted. The simple approach is to make a distinction between the table name or column name in the SQL statement plus the ' [Tab key].


For example, select * from ' order '.


14, through the HTTP protocol to upload multiple files at a time method


There are two ideas, which are two implementations of the same method. Specific procedures also need to design their own:


1. Set up multiple file input boxes in form and name them by array, as follows:


<form action= "" method=post>


<input Type=file name=usefile[]>


<input Type=file name=usefile[]>


<input Type=file name=usefile[]>


</form>


This way, the following tests are done on the server side


echo "<pre>";


Print_r ($_files);


echo "</pre>";


2, in the form to set up multiple file input box, but the name is different, as follows:


<form action= "" method=post>


<input Type=file name=usefile_a>


<input Type=file name=usefile_b>


<input Type=file name=usefile_c>


</form>


Do the same test on the server side:


echo "<pre>";


Print_r ($_files);


echo "</pre>";


Order


I'm pretending to be: Php-4.2.3-installer.exe, you can also go to the latest version, before installing Php-4.2.3-installer.exe to ensure that your IIS6.0 is started and can be accessed. After installation,--> the application configuration on the default Web site;


Step Two: Click on the Web service Extensions--> new Web service extensions;


Step three: Extension-->php, then add;


Step four: Find the path of php.exe add up;


Step five: Be sure;


Step Six: Select the service Extensions for PHP and click Allow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.