Monday, December 17, 2012

Escapes Special Characters in a String for use in an SQL statement

          Today I face a big problem in my recent project with this Quotes ( ' ).  I can't submit my data into database which have contain this Quotes ( ' )  . . . . .  :'(
When i Set my $value= ' my father's ';
with this ( ' ) than i face an error. That  is it -

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's 

Than What...?  What can I do ?

mysql_real_escape_string — Escapes special characters in a string for use in an SQL statement


mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.

This function must always (with few exceptions) be used to make data safe before sending a query to MySQL.

Example :
  1.  $description=$_POST['description'];
  2. $escaped_description=mysql_real_escape_string($description);

  3. $sql= "INSERT INTO TABLE_NAME (post_description)
  4. VALUES                            ('".$escaped_description."')";


This Works Perfectly .....  

  Note : This would allow anyone to log in without a valid password.

Thursday, December 13, 2012

WAMP and Skype Conflict

Recently I discover a conflict between Skype and WampServer that I thought I would Share.  Both of them  use port 80 which causes the conflict... :D . If you run Skype before running Wamp, then Apache will not run. If you go to a site on localhost or 127.0.0.1 , you will probably get a blank screen.
..What Happen..?
The solution is pretty simple. Just make sure you start all services on WAMP before you open Skype. If Skype is disconnected it will work fine. You can then connect Skype once Wamp is running....
--- Really too easy....

But..
A much better solution than starting WAMP before Skype is to follow the advice ---
So, Why not...?
In skype if you click "tools " then "options" and connection down the left, untick the box "use port 80 and 443 as alternative incoming ports"

That worked  nicely and haven't looked back  :)

Sunday, September 9, 2012

Upload a File Into Your hosted Folder


It's too easy to upload a file into your hosted Folder.
At first we need to create a HTML page a Upload.php page  and Create a Folder in the hosting place.

----------------------------------------------------------------------
index.html:
----------------------------------------------------------------------
<head>
      <title>
               Uploading A file
      </title>
</head>
<body>
<table align="center" border="1">
<form enctype="multipart/form-data" action="Upload.php" method="POST">
<tr>
<td>Choose a file to upload:</td>
<td><input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <input name="uploadedfile" type="file"/></td>
</tr>
<tr>
  <td>If the File is Chosen than<br /> Click Upload Button </td>
  <td align="center"><input type="submit" value="Upload File" /></td>
</tr>
</form>
</table>

</body>
----------------------------------------------------------------------

Friday, August 3, 2012

Connect with the PHP MySQL Database



You must create a connection to the database, Than  you can access data in a database. In PHP, it is done with the function name  mysql_connect() .

// mysql_connect("servername","username","password");

Q.What is "servername"?
Ans= It is Optional. Specifies the server to connect to.And the Default value is "localhost".

Q.What is "username"?
Ans= It is Optional.Specifies the username to LOGIN with. The Default value is the name of the User that owns the server process.

Q.What is "password"?
Ans=  It is Optional. Specifies the password to LOGIN with. Default value is "  ". That means NULL.


------------------------------------------------------------------------------
Total code 
------------------------------------------------------------------------------

<?php

session_start();

$connect = mysql_connect("localhost","mint_php","MeHeDi");

//server="localhost" userName= "mint_php " pass=" MeHeDi "

if (!$connect)

  {

  die('Could not connect: ' . mysql_error());

  }
// Here you can write your code

?>
---------------------------------------------------------- 

Wednesday, April 18, 2012

Using Concatenation Operator

Now we are talking about Concatenation.
Concatenation operator (.) [dot] is use to put two string value together.
To concatenate two string value together, use the concatenation operator.      

++++++++++++++++++
<?php
$string1="Hello";
$string2="Welcome to Mint PHP !";
echo $string1. " " .$string2;
?>
++++++++++++++++++
Output:
___________

Hello Welcome to Mint PHP !
______________

There is another method, without using the   .= operator  by this we can join different variable into another variable.
Example:
++++++++++++++++


   <?php
$string1="Hello,";
$string2="World!";
$string3=$string1 . $string2; 
$string4=$string1 . ' and welcome to Mint PHP Blog ' .$string2;

echo $string3.' ' .$string4;

?>

++++++++++++++
Output:
_______

Hello,World! Hello, and welcome to Mint PHP Blog World!
_____________

Saturday, February 18, 2012

Outputting A String

Thank you for reading my Blog.
We have done in previous lesson use PHP " echo " .we can also use the "ptint" function as like as C programming.
You can place either a string variable or you can use quotes,like i do below, to create a string that the echo/print function will output.

**************************************
<body>
<?php
$myString="Hello ! Welcome to Mint PHP ";
echo $myString."<br/>";
echo 'I love PHP :)'."<br/>";
print "You can also use print as like as \"echo\".";
?>

Friday, February 17, 2012

Basic Knowledge About PHP

Do you know what is PHP ?
Here some basic things about PHP.
If you know the  C/C++, HTML,CSS & JavaScript than it will be more easier to understand PHP ?
  • PHP is a server-side scripting language, like ASP.
  • PHP stands for PHP: Hypertext Preprocessor.
  • PHP is an open source software.
  • it's free to download and use.
  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.).
How Can you understand the PHP files ?
  • PHP files can contain text, HTML tags and scripts.
  • PHP files are returned to the browser as plain HTML.
  • PHP files have a file extension of ".php", ".php3", or ".phtml"
Example:index.php

Let's talk about MySQL:

Thursday, February 16, 2012

PHP - Variables

What do you know about PHP variables ?
A variable is a means of storing a value,such as text string "Hello World" or the integer value.
In PHP you define a variable with the following form :
    PHP Variable declaration:
  • $variable_name = "value";
    Example:
  • $myString = "Hello";
Note:
Keep it on your mind,
If you forget that dollar sign at the beginning, it will not work. this is a common mistake for new programmer!


Wednesday, February 15, 2012

PHP White Space


Important things, keep it on your mind.
White Space is ignored between PHP & HTML.
--------------------------------
<html>
<head>
      <title>White Space </title>
<body>
   <?php 
                        echo 'White';
echo 'Space';
echo 'Can not WORK';

?>
</body>
</html>

Tuesday, February 14, 2012

Simple Example of HTML & PHP Page


Here I give an example of one of the easiest  PHP & HTML page that you can create and still follow web standards.


PHP & HTML CODE :
------------------------------
<html>
<head>
      <title>My First PHP Page</title>
<body>
   <?php
                        echo 'Hello World';
?>
</body>
</html>