Q1 . What is SQL injection?How to avoid SOL injection in PHP?
SOLUTION
SQL injection is inserting small bit code that will run in the query and fetch undesired reults thus exposing a wide range of confidential data.We can use some functions like
mysql_real_escape_string()
to escape any special characters form PHP and MySQL perspective.There are a lot of language and platform specific methods to avoid the SQL injection the above mentioned ways are just a beginner's point of view for avoiding to sql injection and are not the complete solution.
Q2 . How to limit data in MySQL?
SOLUTION
We can use LIMIT clause in a query of a MySQL.
LIMIT clause can be used to limit the number of records returned from a query.
Q3 . How to upload file in PHP?
SOLUTION
We can use the following function to upload a file in php
move_uploaded_file()
Q4 . How to navigate to a different page in PHP?
SOLUTION
We can use the header() to direct from one page to another.
header("Location: page2.php");
This will route the page to page2.php
Q5 . How to write contents to php file ?
SOLUTION
The function fwrite() is used to write the contents to a file.The parameters are fwrite(fopen("nameoffile.php","w"),"these are file contents")
The first
Q6 . How to get the name of the current file?
SOLUTION
We can use the $_SERVER["PHP_SELF"] to return the name of the file running the script.
Q7 . How to delete or remove a cookie in PHP?
SOLUTION
We can delete or remove a cookie using the unset function. unset($_COOKIE['name'])
the name is the cookie that was give during cookie creation.
Q8 . How to concatenate two strings in php?
SOLUTION
We can simply use the dot '.' operator to concatenate the strings.
example
$string=$string1+$string2
Q9 . How to print data in PHP?
SOLUTION
We can use the print""; or echo "" functions to print the data.
Q10 . How to send a mail in php?
SOLUTION
We can use the mail function to send the mail to a recepient.
Example to send a mail
mail ($recepient,$subject_of_mail,$Mail_content,$header_data)