Trending February 2024 # Asp.net Web Forms Tutorial: User Controls Examples # Suggested March 2024 # Top 10 Popular

You are reading the article Asp.net Web Forms Tutorial: User Controls Examples updated in February 2024 on the website Daihoichemgio.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 Asp.net Web Forms Tutorial: User Controls Examples

In chúng tôi it is possible to create re-usable code. The re-usable code can be used in many places without having the need to write the code again.

The re-usable code helps in reducing the amount of time spent by the developer after writing the code. It can be done once and reused at multiple places.

In this tutorial, you will learn-

Create User Control in ASP.Net

ASP.Net has the ability to create Web controls. These controls contain code which can be re-used. It can be used across application as per the requirement.

Let’s take a look at an example of how we can create a web user control in ASP.Net

In our example,

We are going to create a web control.

It will be used to create a header component.

It will contain the below mentioned text.”Guru99 Tutorials

“This Tutorial is for ASP.Net”

Let’s work with our current web application created in the earlier sections. Let’s follow the below steps to create a Web user control.

Step 1) The first step is to create a web user control and add it to our Visual Studio Solution.

Step 2) In the next step, we need to choose the option of creating a web user control

We then give a name for the Web Control “Guru99Control”.

You will the see the “Guru99Control” added to the solution.

Step 4) Now it’s time to add the custom code to the Web user control. Our code will be based on pure HTML syntax. Add the following code to the ‘Guru99Control.ascx’ file

Code Explanation:-

In our Web Control file, we are first creating a table element. This will be used to hold 2 rows of text which will be used to display

“Guru99 Tutorials” and

“This Tutorial is for ASP.Net.”

    Next, we define our first table row and put the text as “Guru99 Tutorials.”

    We then define our second table row and put the text as “This Tutorial is for ASP.Net.”

    NOTE: Now we cannot execute this code and show the output. The only way to see if this works is to include it in our application (aspx file). We will see this in the sub-sequent topic.

    Registering User Controls on a chúng tôi web forms

    In the earlier section, we saw how we can create a custom web control. This can be used to display the following two lines in a web form

    “Guru99 Tutorials”

    “This Tutorial is for ASP.Net.”

    Once the custom ‘control’ is created, we need to use it in our web application. The first step is to register the component in our application (Demo.aspx). This is the pre-requisite to use in any custom web control in an chúng tôi application.

    Let’s look at how we can achieve this. The below steps are a continuation to the previous section. In the previous section, we have created our custom control. In this section, we will use the control in our Demo.aspx web form.

    First, we will register our custom ‘control’ into the chúng tôi file.

    The default code consists of steps, which are required to ensure that the form can run as an chúng tôi web form in the browser.

    Step 2) Now let’s add our code to register the user control. The screenshot below shows registration of the user control to the above basic code.

    Code Explanation:-

    The first step is to register the web user control. This comprises of the below basic parameters

    The ‘Register’ keyword is used to register the web user control.

    The src parameter is used to define the name of the control, which in our case is Guru99Control.ascx.

    The tagname and Tagprefix are individual names given to the control. This is done so that they can references in HTML pages as a normal HTML control.

    Next, we reference our Web user control via the TagPrefix:TagName which was assigned earlier. The TagPrefix:TagName is an indicator that we want to use our custom web control. When the page is processed by the web server, you can see we have used the TWebControl:WebControl tag. It will then process the ‘Guru99Control’ chúng tôi our example, it is TWebControl:WebControl.

    An optional ID is given to the control of “Header”. It’s generally a good practice to give an ID to an HTML control.

    Finally, the runat=server attribute so that the control will run on the web server. For all chúng tôi controls, this is the default attribute. All chúng tôi controls (including custom controls) have to be run on the server. Their output is then sent from the server to the client and displayed in the browser accordingly.

    When the above code is set, and the project is executed using Visual Studio. You will get the below output.

    Output:-

    The output message displayed in the browser shows that the web user control was successfully executed.

    Registering chúng tôi controls globally in the web config configuration file asp

    Sometimes one might want to use user controls in multiple pages in a .Net application. At this point, you don’t want to keep on registering user controls on each and every chúng tôi page.

    In .Net you can carry out the registration in the ‘web.config’ file.

    The web.config file is a common configuration file used by all web pages in .Net project.

    It contains necessary configuration details for the chúng tôi web project. For example, one common configuration in the web.config file is the target framework parameter.

    This parameter is used to identify the .Net framework version used by the application.

    Below is a snapshot of the default code in the web.config file. The highlighted part is the target framework part.

    Let’s see how we can register our Guru99Control in the web.config file.

    When you open the web.config file, you might see the below configuration. The ‘web.config’ is added automatically by Visual Studio when the project is created. This is the basic configuration required to make the chúng tôi project work properly.

    Step 2) Now let’s register our component in the web.config file. We need to add the below lines for that.

    The registration comprises of the below substeps

    Then we register the user control with the additional tag. The remaining parameters of tagPrefix, tagName and src remain the same as before.

    Step 3) Remember to go the ‘demo.aspx’ page and remove the lines for control, which had the registration of the Guru99 component. If you don’t perform this step, then the ‘Guru99Control.ascx’ a file will be executed from the ‘demo.aspx’ file instead of ‘web.config’ file.

    The above code is set, and the project is executed using Visual Studio. You will get the below output.

    Output:-

    The output message shows that the web user control was successfully executed.

    Adding public properties to a web control

    Demo Form

    The ‘div’ tag is used to create a section in an HTML document. The ‘div’ tag has a property called a style property. This can be used to give a different style to the text displayed in the div tag. Normally you would see the code for the div tag as shown below.

    So the color attribute is nothing but a key-value pair which gives more information on the tag itself. In the above case, the key name is ‘style’ and the key value is ‘color:#0000FF’.

    Similarly, for user controls, you can create your own properties that describe the control.

    Let’s take a simple example and build upon our ‘Guru99Control’ created in the earlier sections.

    In our example, we are going to add a simple integer property called MinValue. This value would represent the minimum number of characters in the text displayed in the user control.

    Let’s carry out the below-mentioned steps to get this in place.

    Step 1) Open the chúng tôi file. Add the code for adding the MinValue property.

    public int MinValue = 0;

    Code Explanation:-

    The script runat=server attribute is used to indicate that we are adding chúng tôi specific code and that it needs to be run on the web server.

    This is required for processing any property added to the user control. We then add our property MinValue and give it a default value of 0.

    Step 2) Now let’s reference this property in our chúng tôi file. All we are doing now is just referencing the MinValue property and assigning a new value of 100.

    NOTE: – When you run this code, it will not show any output. This is because the output falls under 100 character limit.

    Summary

    ASP.Net has the ability to create user controls. User controls are used to have code which is used multiple times in an application. The user control can then be reused across the application.

    The user control needs to be registered on the chúng tôi page before it can be used.

    To use user control across all pages in an application, register it into the web.config file.

    Properties can also be added to a web user control.

    You're reading Asp.net Web Forms Tutorial: User Controls Examples

    Python Numpy Tutorial For Beginners: Learn With Examples

    What is NumPy in Python?

    NumPy is an open source library available in Python, which helps in mathematical, scientific, engineering, and data science programming. It is a very useful library to perform mathematical and statistical operations in Python. It works perfectly for multi-dimensional arrays and matrix multiplication. It is easy to integrate with C/C++ and Fortran.

    For any scientific project, NumPy is the tool to know. It has been built to work with the N-dimensional array, linear algebra, random number, Fourier transform, etc.

    NumPy is a programming language that deals with multi-dimensional arrays and matrices. On top of the arrays and matrices, NumPy supports a large number of mathematical operations. In this part, we will review the essential functions that you need to know for the tutorial on ‘TensorFlow.’

    Why use NumPy?

    NumPy is memory efficiency, meaning it can handle the vast amount of data more accessible than any other library. Besides, NumPy is very convenient to work with, especially for matrix multiplication and reshaping. On top of that, NumPy is fast. In fact, TensorFlow and Scikit learn to use NumPy array to compute the matrix multiplication in the back end.

    In this Python NumPy Tutorial, we will learn:

    How to Install NumPy

    To install NumPy library, please refer our tutorial How to install TensorFlow. NumPy is installed by default with Anaconda.

    In remote case, NumPy not installed-

    You can install NumPy using Anaconda:

    conda install -c anaconda numpy

    In Jupyter Notebook :

    import sys !conda install --yes --prefix {sys.prefix} numpy Import NumPy and Check Version

    The command to import numpy is:

    import numpy as np

    Above code renames the Numpy namespace to np. This permits us to prefix Numpy function, methods, and attributes with ” np ” instead of typing ” numpy.” It is the standard shortcut you will find in the numpy literature

    To check your installed version of NumPy, use the below command:

    print (np.__version__)

    Output:

    1.18.0 What is Python NumPy Array?

    NumPy arrays are a bit like Python lists, but still very much different at the same time. For those of you who are new to the topic, let’s clarify what it exactly is and what it’s good for.

    As the name kind of gives away, a NumPy array is a central data structure of the numpy library. The library’s name is actually short for “Numeric Python” or “Numerical Python”.

    Creating a NumPy Array

    Simplest way to create an array in Numpy is to use Python List

    myPythonList = [1,9,8,3]

    To convert python list to a numpy array by using the object np.array.

    numpy_array_from_list = np.array(myPythonList)

    To display the contents of the list

    numpy_array_from_list

    Output:

    array([1, 9, 8, 3])

    In practice, there is no need to declare a Python List. The operation can be combined.

    a = np.array([1,9,8,3])

    NOTE: Numpy documentation states use of np.ndarray to create an array. However, this the recommended method.

    You can also create a numpy array from a Tuple.

    Mathematical Operations on an Array

    You could perform mathematical operations like additions, subtraction, division and multiplication on an array. The syntax is the array name followed by the operation (+.-,*,/) followed by the operand

    Example:

    numpy_array_from_list + 10

    Output:

    array([11, 19, 18, 13])

    This operation adds 10 to each element of the numpy array.

    Shape of Array

    You can check the shape of the array with the object shape preceded by the name of the array. In the same way, you can check the type with dtypes.

    import numpy as np a = np.array([1,2,3]) print(a.shape) print(a.dtype) (3,) int64

    An integer is a value without decimal. If you create an array with decimal, then the type will change to float.

    #### Different type b = np.array([1.1,2.0,3.2]) print(b.dtype) float64 2 Dimension Array

    You can add a dimension with a “,”coma

    Note that it has to be within the bracket []

    ### 2 dimension c = np.array([(1,2,3), (4,5,6)]) print(c.shape) (2, 3) 3 Dimension Array

    Higher dimension can be constructed as follow:

    ### 3 dimension d = np.array([ [[1, 2,3], [4, 5, 6]], [[7, 8,9], [10, 11, 12]] ]) print(d.shape) (2, 2, 3)

    Objective Code

    Create array array([1,2,3])

    print the shape array([.]).shape

    What is numpy.zeros()?

    numpy.zeros() or np.zeros Python function is used to create a matrix full of zeroes. numpy.zeros() in Python can be used when you initialize the weights during the first iteration in TensorFlow and other statistic tasks.

    numpy.zeros() function Syntax

    numpy.zeros(shape, dtype=float, order='C')

    Python numpy.zeros() Parameters

    Here,

    Shape: is the shape of the numpy zero array

    Dtype: is the datatype in numpy zeros. It is optional. The default value is float64

    Order: Default is C which is an essential row style for numpy.zeros() in Python.

    Python numpy.zeros() Example

    import numpy as np np.zeros((2,2))

    Output:

    array([[0., 0.], [0., 0.]])

    Example of numpy zero with Datatype

    import numpy as np np.zeros((2,2), dtype=np.int16)

    Output:

    array([[0, 0], [0, 0]], dtype=int16) What is numpy.ones()?

    np.ones() function is used to create a matrix full of ones. numpy.ones() in Python can be used when you initialize the weights during the first iteration in TensorFlow and other statistic tasks.

    Python numpy.ones() Syntax

    numpy.ones(shape, dtype=float, order='C')

    Python numpy.ones() Parameters

    Here,

    Shape: is the shape of the chúng tôi Python Array

    Dtype: is the datatype in numpy ones. It is optional. The default value is float64

    Order: Default is C which is an essential row style.

    Python numpy.ones() 2D Array with Datatype Example

    import numpy as np np.ones((1,2,3), dtype=np.int16)

    Output:

    array([[[1, 1, 1], [1, 1, 1]]], dtype=int16)

    numpy.reshape() function in Python

    Python NumPy Reshape function is used to shape an array without changing its data. In some occasions, you may need to reshape the data from wide to long. You can use the np.reshape function for this.

    Syntax of np.reshape()

    numpy.reshape(a, newShape, order='C')

    Here,

    a: Array that you want to reshape

    newShape: The new desires shape

    Order: Default is C which is an essential row style.

    Example of NumPy Reshape

    import numpy as np e = np.array([(1,2,3), (4,5,6)]) print(e) e.reshape(3,2)

    Output:

    [[1 2 3] [4 5 6]] array([[1, 2], [3, 4], [5, 6]])

    numpy.flatten() in Python

    Python NumPy Flatten function is used to return a copy of the array in one-dimension. When you deal with some neural network like convnet, you need to flatten the array. You can use the np.flatten() functions for this.

    Syntax of np.flatten()

    numpy.flatten(order='C')

    Order: Default is C which is an essential row style.

    Example of NumPy Flatten

    e.flatten()

    Output:

    array([1, 2, 3, 4, 5, 6])

    What is numpy.hstack() in Python?

    Numpy.hstack is a function in Python that is used to horizontally stack sequences of input arrays in order to make a single array. With hstack() function, you can append data horizontally. It is a very convenient function in NumPy.

    Lets study hstack in Python with an example:

    Example:

    ## Horitzontal Stack import numpy as np f = np.array([1,2,3]) g = np.array([4,5,6]) print('Horizontal Append:', np.hstack((f, g)))

    Output:

    Horizontal Append: [1 2 3 4 5 6]

    What is numpy.vstack() in Python?

    Numpy.vstack is a function in Python which is used to vertically stack sequences of input arrays in order to make a single array. With vstack() function, you can append data vertically.

    Lets study it with an example:

    Example:

    ## Vertical Stack import numpy as np f = np.array([1,2,3]) g = np.array([4,5,6]) print('Vertical Append:', np.vstack((f, g)))

    Output:

    Vertical Append: [[1 2 3] [4 5 6]]

    After studying NumPy vstack and hstack, let’s learn an example to generate random numbers in NumPy.

    Generate Random Numbers using NumPy

    To generate random numbers for Gaussian distribution, use:

    numpy.random.normal(loc, scale, size)

    Here,

    Loc: the mean. The center of distribution

    Scale: standard deviation.

    Size: number of returns

    Example:

    ## Generate random nmber from normal distribution normal_array = np.random.normal(5, 0.5, 10) print(normal_array) [5.56171852 4.84233558 4.65392767 4.946659 4.85165567 5.61211317 4.46704244 5.22675736 4.49888936 4.68731125]

    If plotted the distribution will be similar to following plot

    Example to Generate Random Numbers using NumPy

    NumPy Asarray Function

    The asarray()function is used when you want to convert an input to an array. The input could be a lists, tuple, ndarray, etc.

    Syntax:

    numpy.asarray(data, dtype=None, order=None)[source]

    Here,

    data: Data that you want to convert to an array

    dtype: This is an optional argument. If not specified, the data type is inferred from the input data

    Order: Default is C which is an essential row style. Other option is F (Fortan-style)

    Example:

    Consider the following 2-D matrix with four rows and four columns filled by 1

    import numpy as np A = np.matrix(np.ones((4,4)))

    If you want to change the value of the matrix, you cannot. The reason is, it is not possible to change a copy.

    np.array(A)[2]=2 print(A) [[1. 1. 1. 1.] [1. 1. 1. 1.] [1. 1. 1. 1.] [1. 1. 1. 1.]]

    Matrix is immutable. You can use asarray if you want to add modification in the original array. Let’s see if any change occurs when you want to change the value of the third rows with the value 2.

    np.asarray(A)[2]=2 print(A)

    Code Explanation:

    np.asarray(A): converts the matrix A to an array

    [2]: select the third rows

    Output:

    [[1. 1. 1. 1.] [1. 1. 1. 1.] [2. 2. 2. 2.] # new value [1. 1. 1. 1.]] What is numpy.arange()?

    numpy.arange() is an inbuilt numpy function that returns an ndarray object containing evenly spaced values within a defined interval. For instance, you want to create values from 1 to 10; you can use np.arange() in Python function.

    Syntax:

    numpy.arange(start, stop, step, dtype)

    Python NumPy arange Parameters:

    Start: Start of interval for np.arange in Python function.

    Stop: End of interval.

    Step: Spacing between values. Default step is 1.

    Dtype: Is a type of array output for NumPy arange in Python.

    Example:

    import numpy np np.arange(1, 11)

    Output:

    array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

    Example:

    If you want to change the step in this NumPy arange function in Python example, you can add a third number in the parenthesis. It will change the step.

    import numpy np np.arange(1, 14, 4)

    Output:

    array([ 1, 5, 9, 13]) NumPy Linspace Function

    Linspace gives evenly spaced samples.

    Syntax:

    numpy.linspace(start, stop, num, endpoint)

    Here,

    Start: Starting value of the sequence

    Stop: End value of the sequence

    Num: Number of samples to generate. Default is 50

    Endpoint: If True (default), stop is the last value. If False, stop value is not included.

    Example:

    For instance, it can be used to create 10 values from 1 to 5 evenly spaced.

    import numpy as np np.linspace(1.0, 5.0, num=10)

    Output:

    array([1. , 1.44444444, 1.88888889, 2.33333333, 2.77777778, 3.22222222, 3.66666667, 4.11111111, 4.55555556, 5. ])

    If you do not want to include the last digit in the interval, you can set endpoint to false

    np.linspace(1.0, 5.0, num=5, endpoint=False)

    Output:

    array([1. , 1.8, 2.6, 3.4, 4.2]) LogSpace NumPy Function in Python

    LogSpace returns even spaced numbers on a log scale. Logspace has the same parameters as np.linspace.

    Syntax:

    numpy.logspace(start, stop, num, endpoint)

    Example:

    np.logspace(3.0, 4.0, num=4)

    Output:

    array([ 1000. , 2154.43469003, 4641.58883361, 10000. ])

    Finaly, if you want to check the memory size of an element in an array, you can use itemsize

    x.itemsize

    Output:

    16

    Each element takes 16 bytes.

    Indexing and Slicing in Python

    Example:

    ## Slice import numpy as np e = np.array([(1,2,3), (4,5,6)]) print(e) [[1 2 3] [4 5 6]]

    Remember with numpy the first array/column starts at 0.

    ## First column print('First row:', e[0]) ## Second col print('Second row:', e[1])

    Output:

    First row: [1 2 3] Second row: [4 5 6]

    In Python, like many other languages,

    The values before the comma stand for the rows

    The value on the rights stands for the columns.

    If you want to select a column, you need to add : before the column index.

    : means you want all the rows from the selected column.

    print('Second column:', e[:,1]) Second column: [2 5]

    To return the first two values of the second row. You use : to select all columns up to the second

    ## Second Row, two values print(e[1, :2]) [4 5] Statistical Functions in Python

    NumPy has quite a few useful statistical functions for finding minimum, maximum, percentile standard deviation and variance, etc from the given elements in the array. The functions are explained as follows −

    Numpy is equipped with the robust statistical function as listed below

    Function Numpy

    Min np.min()

    Max np.max()

    Mean np.mean()

    Median np.median()

    Standard deviation np.std()

    Consider the following Array:

    Example:

    import numpy as np normal_array = np.random.normal(5, 0.5, 10) print(normal_array)

    Output:

    [5.56171852 4.84233558 4.65392767 4.946659 4.85165567 5.61211317 4.46704244 5.22675736 4.49888936 4.68731125]

    Example of NumPy Statistical function

    ### Min print(np.min(normal_array)) ### Max print(np.max(normal_array)) ### Mean print(np.mean(normal_array)) ### Median print(np.median(normal_array)) ### Sd print(np.std(normal_array))

    Output:

    4.467042435266913 5.612113171990201 4.934841002270593 4.846995625786663 0.3875019367395316 What is numpy dot product?

    Numpy.dot product is a powerful library for matrix computation. For instance, you can compute the dot product with chúng tôi chúng tôi product is the dot product of a and b. numpy.dot() in Python handles the 2D arrays and perform matrix multiplications.

    Syntax:

    numpy.dot(x, y, out=None)

    Parameters

    Here,

    x,y: Input arrays. x and y both should be 1-D or 2-D for the np.dot() function to work

    out: This is the output argument for 1-D array scalar to be returned. Otherwise ndarray should be returned.

    Returns

    The function numpy.dot() in Python returns a Dot product of two arrays x and y. The dot() function returns a scalar if both x and y are 1-D; otherwise, it returns an array. If ‘out’ is given then it is returned.

    Raises

    Dot product in Python raises a ValueError exception if the last dimension of x does not have the same size as the second last dimension of y.

    Example:

    ## Linear algebra ### Dot product: product of two arrays f = np.array([1,2]) g = np.array([4,5]) ### 1*4+2*5 np.dot(f, g)

    Output:

    14 Matrix Multiplication in Python

    The Numpy matmul() function is used to return the matrix product of 2 arrays. Here is how it works

    1) 2-D arrays, it returns normal product

    3) 1-D array is first promoted to a matrix, and then the product is calculated

    Syntax:

    numpy.matmul(x, y, out=None)

    Here,

    x,y: Input arrays. scalars not allowed

    out: This is optional parameter. Usually output is stored in ndarray

    Example:

    In the same way, you can compute matrices multiplication with np.matmul

    ### Matmul: matruc product of two arrays h = [[1,2],[3,4]] i = [[5,6],[7,8]] ### 1*5+2*7 = 19 np.matmul(h, i)

    Output:

    array([[19, 22], [43, 50]]) Determinant

    Last but not least, if you need to compute the determinant, you can use np.linalg.det(). Note that numpy takes care of the dimension.

    Example:

    ## Determinant 2*2 matrix ### 5*8-7*6np.linalg.det(i)

    Output:

    -2.000000000000005 Summary

    NumPy is an open source library available in Python, which helps in mathematical, scientific, engineering, and data science programming.

    numpy.zeros() or np.zeros Python function is used to create a matrix full of zeroes.

    numpy.ones() in Python can be used when you initialize the weights during the first iteration in TensorFlow and other statistic tasks.

    Python NumPy Reshape function is used to shape an array without changing its data.

    Python NumPy Flatten function is used to return a copy of the array in one-dimension.

    Numpy.hstack is a function in Python that is used to horizontally stack sequences of input arrays in order to make a single array.

    Numpy.vstack is a function in Python which is used to vertically stack sequences of input arrays in order to make a single array.

    numpy.arange() is an inbuilt numpy function that returns an ndarray object containing evenly spaced values within a defined interval.

    Numpy.dot product is a powerful library for matrix computation.

    The Numpy matmul() function is used to return the matrix product of 2 arrays.

    Your First Php Web Application Using Mysql And Php With Examples

    Now that Myflixdb, what’s next?

    Congratulations for your success completion of the SQL tutorial series.

    We looked at how we can design a database from scratch, the relational database management system model among others, MySQL as a database management system and how it implements the SQL language, what tools are available for us to use in the database design phase, SQL development and MySQL server administration such as MySQL workbench and finally produced a working database for a fictional video library system “Myflix”.

    Excited as you might be with your newly acquired knowledge, have you given any thoughts’ as to how your database uses will use your database?

    How about developing an simple web application using PHP and MySQL that hides all the SQL statements inside and provide a visual graphical user interface for the users to use when interacting with the database?

    We can use PHP to create sample PHP application with MySQL…

    What is PHP?

    PHP is a general purpose server side scripting language that we can use to develop dynamic web sites and applications. PHP only needs to be installed on the web server that will host the web application and client applications can access the server resources via web browsers. The diagram shown below illustrates the basic architecture of a PHP web application.

    What is PHP?

    Why PHP?

    You have obviously head of a number of programming languages out there; you may be wondering why we would want to use PHP over other languages to develop our video library application? PHP just like MySQL is open source and free, you don’t need to pay for you to get PHP; all you have to do is download it. Packages such as XAMPP come bundled already with a web server, MySQL and PHP among others. This is also unbelievably free. This makes PHP a cost effective choice compared to other scripting languages such as CFML or ASP.

    Other benefit that you get with PHP is that it’s a server side scripting language; this means you only need to install it on the server and client computers requesting for the resources from the server do not need to have PHP installed; only a web browser would be enough.

    PHP also has in built support for working hand in hand with MySQL; this doesn’t mean you can’t use PHP with other database management systems.

    PHP is cross platform which means you can deploy your application on a number of different operating systems such as windows, Linux, Mac OS etc.

    PHP and MySQL

    PHP and MySQL are like two different sides of the same coin. Just like MySQL has built in functions for data manipulations, so does PHP has built in functions for connecting to MySQL server and manipulating the data in the database. Let’s now look at some of PHP functions that allow us to manipulate MySQL databases

    MySQL connect

    $dh = mysql_connect(servername,username,password);

    HERE

    “mysql_connect” is the PHP built in function for connecting to MySQL database

    “servername” is the name of the server running MySQL server.

    “username” is the name of the user that we will use to authenticate ourselves when connecting to the server.

    “password” is the password that we will use to authenticate ourselves when connecting to the server.

    PHP Data Object [PDO]

    Alternatively we can also use the PHP Data Object PDO to connect to MySQL server. It has the following basic syntax.

    $dbconn = new PDO(mysql:host=servername;dbname=databasename,username,password);

    HERE

    “dbconn” is the database connection object that we can use to manipulate our database.

    “new PDO (…)” creates an instance of the PDO class.

    “mysql:host=servername;” is the name of the server running MySQL server.

    “dbname=databasename” is the name of the database to be manipulated from PHP.

    “username,password” are login credentials we will use to authenticate ourselves.

    As you can see from the above PHP sample application database connection examples, not only is PHP simple to use but it’s also flexible. The PHP web application example diagram shown below illustrates how the client application, PHP powered web server and MySQL interact.

    Interaction between PHP and MySQL

    Introducing Myflix Video Library Application

    Assuming we have acquired knowledge of the PHP language combined with what we just learnt in the MySQL tutorial series, we can write the web based application in PHP that runs on top of the MySQL database to provide our Myflix database users with a Visual Graphical User Interface for interactions.

    Myflix Video Library Screenshots

    The screenshots of PHP MySQL example below show how the video library application running on top of Myflixdb would look like.

    MyFlix Video Library

    Members listing window shown in the above PHP with MySQL project:

    MyFlix Video Library

    Movie details editing window shown above

    Summary

    MySQL is a powerful open source database engine that can meet the requirements of both stand-alone as well as client server applications.

    PHP is a general purpose scripting language that can be used to develop client applications that run on top of MySQL databases.

    Equipping yourself with both MySQL and PHP web application development knowledge is double blessing.

    A Guide To Payroll Forms For Employers

    When welcoming a new hire to the team, small business owners must do a lot more than train them on their positions. One big task is making sure new employees get paid properly and that all the necessary payroll forms are filled out correctly.

    While owning a business can be rewarding on many levels, managing payroll forms might be a pain if you’re not familiar with the ones you need. There are many forms to consider depending on your employees and business type, and it’s important to get them right.

    The Internal Revenue Service penalizes businesses for filing incorrectly or failing to pay employment taxes. Fines vary by charge level, with federal offenses typically more expensive than state ones. In previous years, the IRS implemented nearly 7 million payroll tax penalties, which amounted to $4.5 billion. This is a sign of how seriously the IRS takes these penalties and why it’s important to understand each form and when it’s due.

    Editor’s note: Looking for the right payroll service for your business? Fill out the below questionnaire to have our vendor partners contact you about your needs.

    What payroll tax forms do you need to know about?

    Missing a payroll tax deadline or filing the wrong form can have expensive consequences. Below we’ll explain the payroll report forms that you need to keep on your radar.

    Form nameDue dateForm 941April 30, July 31, Oct. 31, Jan. 31Form 944Jan. 31Form 940Jan. 31Form W-2Jan. 31Form W-3Jan. 31Form 1095-BJan. 31Form 1094-BFeb. 28Form I-93 days after the hire dateForm W-9At the time contract work is orderedForm 1099-MISCMarch 1 if filed by paper, March 31 electronicallyForm 1099-NECJan. 31 (to recipient and IRS)Form W-4Feb. 15Form 8027March 1 if filed by paper, March 31 electronically

    Payroll report forms

    A payroll report form informs the government of your employment tax liabilities. On this form, document the taxes you withheld from employee wages and the payroll taxes you paid. Be sure to submit payroll reports for both federal and state taxes.

    1. Form 941

    Source: IRS

    Form 941, the Employer’s Quarterly Federal Tax Return, reports the number of employees you have, their wages and taxable tips, and the federal income taxes you withheld. Social Security, Medicare taxes and sick pay are also documented here, along with any adjustments made to them. You must file this payroll tax form unless you have already submitted a final return, are a seasonal employer, or employ farm or household workers. A payroll form should be filed quarterly.

    Due dates: April 30, July 31, Oct. 31, Jan. 31

    2. Form 944

    Very small businesses sometimes use Form 944 instead of Form 941. This form is the Employer Annual Tax Return, and the only businesses that qualify to use it are those with $1,000 or less in annual liabilities for Social Security, Medicare and federal income taxes. Additionally, you must have a written notification from the IRS permitting you to use this form instead of Form 941. This payroll tax form is submitted annually instead of quarterly, so if you’re qualified to use it, you should.

    Due date: Jan. 31

    3. Form 940

    Form 940 is the Employer’s Annual Federal Unemployment Tax Return. This payroll tax form is used to report the federal unemployment tax, or the FUTA tax, in reference to the Federal Unemployment Tax Act. This tax funds unemployment compensation to employees who have recently lost their jobs. Your business must pay FUTA taxes if you paid at least $1,500 in wages in a quarter within the past two years. These taxes are paid quarterly but reported once per year.

    Due date: Jan. 31

    4. Form W-2

    Source: IRS

    The W-2 is one of the better-known forms and should be given to each employee at the end of each year. It is used to report each employee’s annual compensation and all federal, state, and other payroll tax withholdings. This does not need to be filled out for independent contractor workers; you’ll fill out Form 1099 for them instead.

    Due date: Jan. 31

    5. Form W-3

    The W-3 is a condensed version of your W-2 forms. For example, one W-3 can represent 10 W-2s. This form is called the Transmittal of Wage and Tax Statements. It includes total earnings, FICA wages, federal income wages, and tax amount withheld. You do not need to give W-3s to your employees. Your W-3 should be sent to federal and state governments along with your W-2 forms.

    Due date: Jan. 31

    6. Form 1095-B

    If you provide a health insurance plan for your employees that meets or exceeds what the Affordable Care Act (ACA) calls “minimum essential coverage,” file Form 1095-B. On it, you’ll note the type of health insurance, whether dependents are covered, and the coverage period for the prior year. Your employees will use this form to prove they have qualifying health insurance that exempts them from paying a penalty when they file their tax returns. If your business has at least 50 full-time employees and is what the ACA calls an “applicable large employer,” fill out Form 1095-C instead.

    Due date: Jan. 31

    7. Form 1094-B

    Form 1094-B is the Transmittal of Health Coverage Information Returns, which is similar to the W-3 in that it summarizes Form 1095-B with the number of forms you’re submitting. It also gives the IRS your name and phone number so it can contact you if it has questions about the forms. You don’t have to send Form 1094-B to employees; submit it to the IRS along with the 1095-B forms. If your business is classified as an “applicable large employer,” fill out Form 1094-C instead.

    Due date: Feb. 28

    8. Form I-9

    Form I-9 must be included as part of your onboarding package for new hires. The form confirms employee eligibility within the United States. Both U.S. citizens and non-citizens complete Form I-9 before receiving payment for their work. The employee attests authorization to work in the United States while providing documentation (like a birth certificate or driver’s license) to prove eligibility. Employers must review the documents and confirm that the papers appear genuine and are not falsified. The employer should keep Form I-9 on file in case of government review.

    The Department of U.S. Citizenship and Immigration Services states that the form is required within three days of hiring a new employee. For example, if the employee starts work on a Tuesday, the form must be submitted to the employer by that Friday.

    Due date: Three days after the hire date

    9. Form W-9

    Source: IRS

    Form W-9 is specifically for companies that hire independent contractors. If the company pays the independent contractor more than $600 in a tax year, the company must report those payments to the IRS using Form 1099-MISC. On Form W-9, the employer asks the contractor (or freelancer) for the tax filer’s name, address, and tax identification number. Since the W-9 is not filed, there isn’t a specific due date for the form. However, companies should request the form be completed before paying the independent contractor.

    Due date: At the time contract work is ordered

    10. Form 1099-MISC

    Use the 1099-MISC form when you make a payment of $600 or more to an individual or LLC. This includes attorney fees, awards, healthcare, royalties and rents.

    Due date: March 1 if filed by paper, March 31 if filed electronically

    FYI

    Form 1099-MISC is no longer used to report compensation given to freelancers, contractors, etc. All non-employee-provided services should be reported on Form 1099-NEC.

    11. Form 1099-NEC Beginning with the 2023 tax year, the 1099-NEC is a simplified way to report over $600 paid to a self-employed individual, freelancer, or contractor who supplied services to your business. The 1099-NEC covers fees, benefits, commissions, prizes, awards, etc., for non-employee-provided services.

    Due date: Jan. 31 (distributed to recipients and filed with the IRS)

    12. Form W-4

    Source: IRS

    Provide a W-4 form to all new hires. Employees receiving the form should complete it before or on the first day of their new job. Form W-4 provides the employer with personalized tax withholding information that aids in maintaining an accurate payroll. Holding a W-4 for each employee streamlines the W-2 form preparation.

    Due date: Feb. 15

    13. Form 8027

    Form 8027 is not a standard form. It only applies to companies employing more than 10 workers on a normal business day in industries where tipping is customary. Hospitality and food service companies are the most common industries that will use Form 8027. It reports any tip income an employee received while working directly for the business. If the tip amounts are too low for the size of the business, the company may be required to pay out allocated tips. Form 8027 calculates this formula for any amounts due.

    Due date: March 1 if filed by paper, March 31 if filed electronically

    What’s a payroll direct deposit form?

    A payroll direct deposit authorization form allows employers to send money to employees’ bank accounts. Most employers ask employees to provide a voided check to fill out the form, as it provides the ABA routing number that identifies the employee’s bank and account number. After the employee signs the form and gives it back to the employer, their money can be sent directly to their account.

    Banks typically use the Automated Clearing House to coordinate these payments. This solution is not only greener and more secure than paper checks, it also cuts out the hassle of depositing a check or waiting for it in the mail.

    What are certified payroll forms?

    Businesses with government contracts need to submit a certified payroll form, also known as Form WH-347. When a payroll report is certified, it means employees have been paid according to the Davis-Bacon Act prevailing wage requirement. Certification includes a signed statement of approval that confirms the payroll forms are complete and correct.

    A certified payroll report includes the names of every employee, the nature of the work they did, wages, hours worked, and amounts withheld. It’s typically due on the last day of the payroll period.

    When filing certified payroll forms, keep in mind that every state has its own requirements and may ask for multiple forms and filings. Be careful not to overlook your state’s conditions.

    How do you add an employee to payroll?

    Adding an employee to payroll takes some prep work. Creating a payroll structure that works for your business and complying with federal and state labor laws streamlines the process of adding new employees.

    Step 1: Obtain an EIN (employer identification number) from the IRS by submitting Form SS-4. You may also need to get state and local tax IDs.

    Step 2: Verify that your new employee is eligible to work in the U.S. For you to do this, your employee must fill out the employment eligibility form, Form I-9, and an employee’s withholding certificate, better known as a W-4, to make sure you withhold the correct tax amounts from each paycheck.

    Step 3: Schedule pay periods and have compensation plans for holidays, vacations and other forms of leave.

    Step 4: Once you have the completed forms from your employee, add them to your payroll. If you use a top payroll service, you’ll need to contact the company to add your new employee to your plan. Always report your payroll taxes to the IRS on time to avoid penalties.

    Tip

    To avoid payroll headaches, read our article on the four most common payroll issues and how to avoid them.

    What’s the difference between a payroll status change form and a payroll deduction form?

    Payroll status change forms and deduction forms accomplish different things, but you need both when hiring employees. 

    Payroll status change form

    As your business grows, you may have an employee whose status or position changes. This can affect their pay, whether they work full or part time, their position or job title, and the department in which they work. It’s important to document these changes with a payroll status change form, which is then placed in the employee’s personnel file as part of their employment history.

    Payroll deduction forms

    A payroll deduction form does just what its name suggests: It helps you determine and record how much money will be withheld from an employee’s payroll check. Some deductions are mandatory, such as taxes, while other deductions are voluntary, like 401(k) plans, insurance plans, and union and uniform dues. Court-ordered payments, such as child support payments, may also be garnished from employee wages. This form gives your payroll provider the information it needs to withhold the proper amounts from your employees’ paychecks.

    Tips to avoid payroll mistakes

    There’s no shame in asking for help. If you’re unsure how to set up payroll for your employees, or if you want to save yourself the trouble of navigating payroll regulations, sign up for a payroll service or hire an accountant. It’s better to pay for the service and have it done correctly than to pay fines for your mistakes. Here are three tips to help you avoid common payroll mistakes:

    Pay attention to deadlines for tax payments and filing. Depending on your business, you may have payroll tax payments due annually or quarterly.

    Don’t miscalculate overtime. Some states have their own overtime regulations, and in those cases, the regulation that will give the employee higher pay prevails. Check your state’s labor laws beforehand to ensure you’re paying your employees fairly.

    Set aside time for processing payroll. Late paydays lead to unhappy workers, and rushing can cause costly mistakes. If you overpay or underpay your workers, not only will you have to take time to make the correction, you may also face fines.

    Julie Thompson contributed to the writing and research in this article.

    How To Embed Google Forms On Your Website

    If you’re struggling to get a form on your site, you could install a plugin for basic functionality, but that may further slow down your site if you already have many plugins.

    With Google Forms, you not only get to add a form to your site faster, but you also get more features. For instance, you can insert media files, import questions, integrate easily with WordPress and email, share on more platforms, and enjoy additional storage in Google Drive.

    Table of Contents

    Additionally, Google Forms allows you to collaborate with your teammates, and track all results from your forms from different channels, not just your site.

    Here’s how you can quickly embed Google Forms on your website in just a few simple steps.

    How to Embed Google Forms on Your Website

    To get started, you’ll need a Google Form and its embed code, which you’ll add to the page or post where you want the form to appear on your site.

    Create a Google Form

    Select the Blank tile from the toolbar to create your form from scratch, or select a template from the available options.

    Add a title and description to your form.

    Next, use the toolbar on the right to add questions, import questions from a different form, upload videos and images, or add a section. 

    If you want to choose the answer type, select the arrow next to the answer type section.

    From the options, you can choose to let users leave a short answer or paragraph, multiple choice, mark checkboxes, or select choices from a dropdown menu.

    To customize or change the form’s theme, use the palette icon at the top right side of the screen.

    You can also preview the final design using the eye icon before saving and embedding it on your website.

    If you want to collect email addresses, limit users to one response each, or allow them to edit their responses after submitting the form, select the Advanced Settings (gear icon).

    Select the three-dot icon for more options such as adding collaborators, undoing actions, adding preferences, or add-ons from Google Workspace Marketplace.

    Note: Selecting Add Collaborators specifically allows you to invite members of your team to work on the form. You can send invites using the link-sharing option or type in their email addresses and they’ll receive an email notification with the invite.

    Embed Your Google Form on Your Website

    Now that you have your Google Form ready, the next step is to add it to your website. To do this, you need to get the form’s embed code, which is a unique code snippet that you’ll add to the page or post where you want the form to appear.

    To get the form’s embed code, select Send at the top right side of the form editor window.

    In the Send form, you’ll see various options you can use to share the form for example via a link, email, social media, or HTML. You can choose whether to share the form on Facebook or Twitter, or send it to your email list of subscribers.

    In the Embed HTML field, you’ll see a code snippet, as well as the width and height boxes where you can change the size dimensions for your embedded form.

    Select Copy to copy the embed code and go to your website’s dashboard.

    Add Your Google Form’s Embed Code to Your Website

    Now that you have your embed code, sign in to your site’s admin dashboard and go to the page or post where you want to embed the form.

    Note: Instructions in this guide apply to WordPress using the Gutenberg/Block Editor.

    The first step is to add a custom HTML block. To do this, open the block editor by selecting Pages or Posts in the admin panel and find the page or post you want to edit.

    Select Add block (+) icon at the top left side of the block editor next to the WordPress logo.z

    Go to the Formatting section and scroll down to find and select Custom HTML.

    Paste the HTML code snippet you copied earlier into the field provided.

    In the Custom HTML block’s toolbar, select the Preview tab to see a preview of how your form will appear on your website.

    Your Google Form will appear on your page or post.

    Make sure you update your post or page after editing for the changes to be saved.

    Craft the Perfect Form for Your Site

    Whether you want to add a survey to your site, an order form to your online store, event registration, or contact form, Google Forms can help you create the perfect forms for your website. 

    Check out our guides on how to embed Google Calendar on your website and how to create your own coupon popup in WordPress for added functionality and better user experience.

    User Defined Function In Excel

    Excel User Defined Function (Table of Contents)

    Start Your Free Excel Course

    Excel functions, formula, charts, formatting creating excel dashboard & others

    Introduction to Excel User Defined Function

    Excel has reached a source of inbuilt functions to make your life easy when analyzing data. However, that is not the end. Sometimes, you might come up with a situation where all the formulae provided must be more suitable for your task. In such cases, you can create your function in Excel with the help of VBA; such functions are called User Defined Functions (UDFs). UDFs can be used within the worksheet the same way you use the normal Excel functions such as SUM, AVERAGE, etc. These functions can be created per the user’s requirement through VBA and ease the user’s tasks in Excel. In this article, we will discuss the User Defined Function in Excel.

    Any UDF has a basic rule; you need to define it under a FUNCTION procedure instead of a subroutine procedure (sub-procedure we generally use). Using the FUNCTION procedure, we can create UDFs and use them inside Excel as the general Excel functions such as SUM, AVERAGE, VLOOKUP, etc.

    Examples to Create User Defined Function

    Let’s understand how to create the User Defined Functions in Excel with some examples.

    You can download this User Defined Function Excel Template here – User Defined Function Excel Template

    Example #1 – User Defined Function to Find the Area of Triangle

    Students from the mathematical stream may always have a problem where they need to find a triangle area. Though it has a very easy formula to work around, students will be pleased if they have some function that can compute the area of a triangle. Follow the steps below to create a function that can compute the area of a triangle.

    Step 2: Define a new FUNCTION procedure with the name as TriangleArea. This name will be used to find this function in Excel.

    Since it is a FUNCTION procedure, we must set the arguments to calculate the triangle area while defining the function.

    Step 3: After TriangleArea, mention height and base as two arguments to this function in the bracket. These are the mandatory arguments. The user needs to provide values for height and base to calculate a triangle’s area. The FUNCTION procedure is complete (you can see the End Function clause), and we can write pieces/lines of code within this procedure.

    Step 4: Now, we will write a code that will return the area for a triangle when we provide the height and base values within this procedure. Since the area of the triangle is formulated as we will formulate it under the code and assign it to TriangleArea.

    Suppose we have different height and base values, and we need to capture the area of a triangle for those values using the function we just have created. This is it; the function is created and can be used. Save the code, and we will see how it works for the different values of height and base.

    Step 5: In cell C2, start typing the formula =TriangleArea(A2, B2) to compute the area of a triangle and provide height and base as an argument to the same formula.

    Drag the formula to get the area for the second and third values of height and base.

    Example #2 – User Defined Function to Square any Number

    Suppose we want the squared value of any number (integer or float). No such function gives you the squared value for any number. Let’s create one that can do the task for you in Excel.

    Step 1: In the same module, start defining a new FUNCTION procedure for squaring a number with the name SquareNum.

    Step 2: We need to add an argument for the function. Use num as an argument to the function within parentheses. As soon as you provide an argument within the function, you will be able to see the End Function statement, which means the arguments we have provided are accepted,

    Step 3: We can add the code/lines to get the square of numbers within the function. As num is the argument to the SquareNum function, we have two options to get the desired output. One way is to multiply num by itself (num * num ex. 2 * 2), or another way is to use the power operator “^” over the num function (num^2 ex. 3^2). I will go with the other way as it makes the code more versatile.

    Suppose we have a set of different numbers, as shown in the image below, and we need to find the square values for those. We can use the SquareNum function defined just above to get the result.

    Step 6: Provide A2 as an argument to this function so that it will square the number present in cell A2.

    Step 7: Close the parentheses to complete the formula and press Enter key to see the square of number 11 (number in cell A2).

    Step 8: Drag and Paste the formula across the remaining cells to find the square roots of the numbers provided.

    This article emphasized creating User Defined Functions in Excel, which can reduce the man’s work. Let’s wrap things up with some points to be remembered.

    Things to Remember About User Defined Functions in Excel

    UDF, through VBA, helps create custom formulas that can reduce the time we need to do any task and simplify the tasks.

    Recommended Articles

    This is a guide to User Defined Functions in Excel. Here we discuss how to create a User Defined Function in Excel, practical examples, and a downloadable Excel template. You can also go through our other suggested articles –

    Update the detailed information about Asp.net Web Forms Tutorial: User Controls Examples on the Daihoichemgio.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!