Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

My way learn MySQLI and PHP by examples

My way learn MySQLI and PHP by examples

MySQL is world most used database and when its works PHP then they have no match. Learning MySQL is very is one can found thousand of tutorial on net but these are now old as MySQLI(or MySQL Advanced) next version are now on demand as implementation is easy, secure and little bit faster. In this tutorial I am going to share Uses of MySQli in your next project.

MySQLI and PHP by examples

For Connecting to database, create a PHP file name dbsettings.php with following code :
$sanjay=new mysqli(‘localhost’,’root’,”,’mysqlifirst’);
echo $sanjay->connect_error;
I think above line is quite easy to understand, mysqlifirst is the name of your database.

Data query :
Suppose you have a table name billings which has coloumn trans_id, amount and so on.
Create a another file name dataquery.php with following code:

$query=”select * from billings where trans_id=’2013′ “;
echo “Transaction ID. 2013 amount is Rs.”.$rows[‘amount’];
This is I think a very simple example of using MySqli. If you have any doubt then comment below , I will try to explain it later.
+Sanjay Prasad

Upload user profile image and save to data base -PHP MYSQLI

Upload user profile image and save to data base -PHP MYSQLI

 If you are working on customized CMS or Social networking website then user profile image may be or may not be a head ache I have developed my own where we can upload and rename the image username.jpg/png/gif with size restriction to 200KB.

PHP MYSQLI Upload Image Tutorial

First design a table where database name is Sanjay.
Create a table userImage  fileds
user – username will be stored
url – url of img stored
lastUpload- when the upload was done.
Create a folder upload/   where  all images will stored.

$user=”sanjay”; //you can fetch username here
$db=new mysqli(‘localhost’,’root’,”,’Sanjay’);
echo $db->connect_error;
$pull=”select * from userImage where user=’$user'”;
$allowedExts = array(“jpg”, “jpeg”, “gif”, “png”,”JPG”);
$extension = @end(explode(“.”, $_FILES[“file”][“name”]));
if ((($_FILES[“file”][“type”] == “image/gif”)
|| ($_FILES[“file”][“type”] == “image/jpeg”)
|| ($_FILES[“file”][“type”] == “image/JPG”)
|| ($_FILES[“file”][“type”] == “image/png”)
|| ($_FILES[“file”][“type”] == “image/pjpeg”))
&& ($_FILES[“file”][“size”] < 200000)
&& in_array($extension, $allowedExts))
if ($_FILES[“file”][“error”] > 0)
echo “Return Code: ” . $_FILES[“file”][“error”] . “<br>”;
echo ‘<div class=”plus”>’;
echo “Uploaded Successully”;
echo ‘</div>’;echo”<br/><b><u>Image Details</u></b><br/>”;

echo “Name: ” . $_FILES[“file”][“name”] . “<br/>”;
echo “Type: ” . $_FILES[“file”][“type”] . “<br/>”;
echo “Size: ” . ceil(($_FILES[“file”][“size”] / 1024)) . ” KB”;

if (file_exists(“upload/” . $_FILES[“file”][“name”]))
unlink(“upload/” . $_FILES[“file”][“name”]);
move_uploaded_file($_FILES[“file”][“tmp_name”],”upload/”. $user.”.”.$ext);
echo “Stored in as: ” . “upload/”.$user.”.”.$ext;

$query=”update userImage set url=’$url’, lastUpload=now() where user=’$user'”;
echo “<br/>Saved to Database successfully”;
echo “File Size Limit Crossed 200 KB Use Picture Size less than 200 KB”;
<form action=”” method=”post” enctype=”multipart/form-data”>
echo ‘<div class=”imgLow”>’;
echo “<img src=’upload/$pics[url]’ alt=’profile picture’ width=’80 height=’64’ class=’doubleborder’/></div>”;
<input type=”file” name=”file” />
<input type=”submit” name=”pupload” class=”button” value=”Upload”/>

Hope You will understand this simple script.

Tutorial is update on 31 May 2017, working fine tested on  XAMPP Version 7.0.8

if you want complete script with foundation framework, profile mangement, password change, user profile picture management then download my open -source project Adminplus at githhub
download Zip file extract and save it to htdocs folder , if using Linux set permission . open phpmyadmin and create a database sanjay_plus now import  sql . Now we can login using username sanjay password

Ubuntu 12.10 failed to impress people

Ubuntu 12.10 failed to impress people

I am a big fan of Ubuntu using since it launched 6.04 till ubuntu 12.10 64 bit. It always gave something interesting  and innovative. The biggest plus point of ubuntu is its stability and speed and Linux each and every distro secure. But the experience that I got from 12.10 is pathetic.System Tested
Acer Emachine
2.13 GHz Dual Core
OS – Ubuntu 12.10 64 bit

Booting from Live USB (763MB) was a awesome experience better than 12.04. Installation went smooth and took around 15 minutes to install. Desktop was responsive but not as 12.04.
Updated Software Sources , then install Gnome 3 Shell and after reboot I was back to my favourite Gnome default desktop it was responsive compare to unity desktop. By default you will find a power off option so shut down and restart become easy.

Ubuntu 12.10 and its Problems
Package Selection- distro comes in 763MB iso but didnot provide GIMP or Cheese.
Software Install issue – You will not able to run 32 bit application as Ubuntu 12.10 not ready to install Wine.
As it has some dependecy issues installing ia32-lib
sudo apt-get install ia32-lib
also fails gives output

Unable to correct problems, you have held broken packages.

So you will not able to install Wine 1.5/1.4 , XAMPP (PHP MySQL Development).

Media Playback
After installing flash and necessary codecs everything runs smooth and experience was good.

Conclusion : Unity Desktop was not mature compare to Gnome 3 default desktop, user interface was average on unity, You will find not able to install some software  , I will recommend OpenSuse 12.2 Gnome , Linux Mint Mate ,stick back to ubuntu 12.04 or wait for ubuntu next release.