Skip to main content

Posts

Showing posts from March, 2018

Simple mysqli connection and some tips

Simple mysqli connection: <?php $conn1=mysqli_connect("localhost","root","","databasename"); if($conn1) {     echo "<script>console.log('Connection ok');</script>"; }else{     echo "<script>console.log('Connection not ok');</script>"; } ?>   Mysqli is the improved version of mysql. Now-a-days whenever you write mysql, it will show you error as mysqli is introduced. To use mysqli such as mysqli_query all you need to do is just put your connection name Ex: $conn1 (like our code) in your mysqli_query. Ex: mysqli_query($conn1, "SELECT * FROM databasename");  Some mysqli functions which is used frequently are given below: mysqli_query()  mysqli_num_rows() mysqli_fetch_assoc() mysqli_fetch_array() mysqli_close() mysqli_connect_error() mysqli_error() mysqli_fetch_all() mysqli_free_result()

PHP Warning: Division by zero?!

PHP Warning: Division by zero?! STEP 1:    This warning can happen if a variable is not set then it is NULL and if you try to divide something by null you will get a divides by zero error. For example:  This code will occur error:   $get_likes = mysqli_query($conn1,"SELECT * FROM ratings WHERE videoid='$videoid' AND type='like'"); $num_of_likes = mysqli_num_rows($get_likes); $get_dislikes = mysqli_query($conn1,"SELECT * FROM ratings WHERE videoid='$videoid' AND type='dislike'"); $num_of_dislikes = mysqli_num_rows($get_dislikes); $total_num = $num_of_likes + $num_of_dislikes; $width_of_one = $total_width / $total_num; Now in this code, I've pointed out (red mark) the like for this line it will show division by zero error as it is trying to divide something by null. So, to remove this error what we can do is, we can simply put a @ sign before $num_of_likes + $num_of_dislikes. Example:   $...

How to set file size in Xampp!

Method 1:  At first, Open your Xampp folder, and find out php folder. ex: find php folder And then open your php folder and find out php.ini . ex: php.ini Open your php.ini file (if it is giving permission to edit ) and it will open in notepad. and in notepad click, edit -> find -> write (file uploads) and click find next and this will appear: file uploads find upload_max_filesize. By default, Upload_max_filesize will be 2M. change it to 128M, like i did in the picture. Don't forget to give the M after 128. Ex: 128M. And that's it , you are good to go. Method 2: (.htaccess) If php.ini don't give responses or don't give permissions! Than method 2 is for you... click on htdocs and open your project. and open your .htaccess file of that project in notepad++ or notepad. If you don't have any .htaccess file! than create one. Now,open your .htaccess file and write the following code: php_value upload_max_filesi...