PHP Select Data From MySQL

The SELECT statement is used to select data from one or more tables: include (‘function/db.php’); global $conn; $id = “1”; $query = “SELECT * FROM table WHERE id=’$id’”; $result = $conn->query($query); $row = $result->fetch_assoc(); $id = $row[‘id’]; $data1 = $row[‘col1’]; $data2 = $row[‘col2’];         $data3 = $row[‘col3’];         $data4Continue reading “PHP Select Data From MySQL”

Password Change With Old Password

Change your Password With Your Original Password   if(isset($_POST[‘changepassword’])) { $cp = $_POST[‘currentpass’]; $np1 = $_POST[‘newpass1’]; $np2 = $_POST[‘newpass2’]; $id = $_POST[‘id’]; $chck = $conn->query(“select * from profile WHERE id=’$id’”); $r = $chck->fetch_assoc(); $opass = $r[‘pass’]; if($np1 != $np2) { $_SESSION[‘passwordchange’] = “New Password Not Match!”; header(‘Location: ‘ . $_SERVER[‘HTTP_REFERER’]); } else if($cp != $opass)Continue reading “Password Change With Old Password”

Insert into DB using ajax without refreshing page

Create a new file call ajax.php and add js-script to an index file or add a new js file. index.php <form> <input class=”form-control” type=”text” id=”name” /> <input class=”form-control” type=”text” id=”contact”  /> <button class=”btn btn-primary” type=”button”  onclick=”insert()”>Add Details</button> </form> // show the result .js script   function insertm() { var mnm = $(‘#name’).val(); var mcon = $(‘#contact’).val(); if(mnm ==Continue reading “Insert into DB using ajax without refreshing page”

How To Get Difference between two dates

Get Difference between two dates   Date1 – dd-mm-yyyy Date2 – dd-mm-yyyy Break and get the part of the date, month and year and show the difference. $today = date(“d-m-Y”); $d1 = substr($d, 0,-8); $d2 = substr($today, 0,-8); $m1 = substr($d, 3,-5); $m2 = substr($today, 3,-5); $y1 = substr($d, -4); $y2 = substr($today, -4); $date1Continue reading “How To Get Difference between two dates”

Get the Only Date part from DateTime SQL

Get the only date from date time in database   Real Datetime shows like – yyyy-mm-dd hh:mm:ss And Now you can break and get the part of the date, time as per your requirement. $dd = substr($date, 8,2); $mm = substr($date, 5,2); $yyyy = substr($date, 0,4); $newdate = “$dd-$mm-$yyyy”; And you can show your resultContinue reading “Get the Only Date part from DateTime SQL”

Empty a folder on the server

Make sure you have unique name directory $directory = “images/directory”; empty($directory); function empty($directory) { $dirHandle = opendir($directory); // Loop over all of the files in the folder while ($file = readdir($dirHandle)) { // If $file is NOT a directory remove it if(!is_dir($file)) { unlink (“$directory”.”$file”); // unlink() deletes the files } } // Close theContinue reading “Empty a folder on the server”

Upload a folder to the server and files inside too.

Make sure you have a directory on your server   function addfolder() { $directory = “images/”; $count = 0; if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’){ foreach ($_FILES[‘files’][‘name’] as $i => $name) { if (strlen($_FILES[‘files’][‘name’][$i]) > 1) { if (move_uploaded_file($_FILES[‘files’][‘tmp_name’][$i], ‘$directory/’.$name)) { $count++; } } } echo “Folder uploaded! Successfully!”; } }

See The Error Occur Last During Query

We are going to take error message into session include(‘db.php’); global $conn; $run = mysqli_query($conn, “insert into table(column) values (‘testing’)”); if($run){ $_SESSION[‘msg’] = “success!”; } else { $_SESSION[‘msg’] = mysqli_error($conn); } To Print Here is The Code – if(isset($_SESSION[‘msg’])){ echo $_SESSION[‘msg’]; unset($_SESSION[‘msg’]); } //run only once Result Will Shown Like – You have an error in yourContinue reading “See The Error Occur Last During Query”

Design a site like this with WordPress.com
Get started