How to Add Auto Increment to a Column in PostgreSQL ?

How to Add Auto Increment to a Column in PostgreSQL ?

Here’s a tailored post for your website using the requested keywords:


By Basant Mallick, Freelance PHP Developer in Delhi

As a freelance PHP developer in Delhi, I often work with PostgreSQL, a powerful open-source relational database system. One common requirement when designing database tables is to add an auto-increment feature for a column, usually for primary keys. In this guide, I’ll walk you through the process of setting up auto-increment in PostgreSQL.


What Is Auto Increment?

Auto-increment allows a database column to automatically generate a unique value for each row inserted into a table. In PostgreSQL, this is typically achieved using a SERIAL or IDENTITY column.


Steps to Add Auto Increment in PostgreSQL

1. Create a New Table with Auto Increment

If you’re creating a new table, you can define a column with the SERIAL or GENERATED AS IDENTITY type. Here’s an example:

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL
);

The SERIAL keyword automatically creates a sequence behind the scenes and sets it up as the default value for the id column.


2. Modify an Existing Table to Add Auto Increment

If you need to add auto-increment functionality to an existing column, follow these steps:

  1. Add a Sequence: CREATE SEQUENCE users_id_seq;
  2. Set the Default Value Using the Sequence: ALTER TABLE users ALTER COLUMN id SET DEFAULT NEXTVAL('users_id_seq');
  3. Associate the Sequence with the Column: ALTER SEQUENCE users_id_seq OWNED BY users.id;
  4. Optional: Update Existing Values
    If your table already has data, make sure the sequence starts at the right value: SELECT SETVAL('users_id_seq', MAX(id)) FROM users;

3. Use GENERATED AS IDENTITY (PostgreSQL 10 and Later)

In newer PostgreSQL versions, the GENERATED AS IDENTITY feature is recommended as it offers more flexibility and is ANSI SQL-compliant. Example:

CREATE TABLE orders (
    order_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    product_name VARCHAR(255)
);

Why Choose PostgreSQL for Your Projects?

As a freelance PHP developer in Delhi, I recommend PostgreSQL for its reliability, scalability, and advanced features. Whether you’re building a small application or a complex enterprise system, PostgreSQL has the tools you need.


Need Help with Database Setup?

If you’re looking for an experienced freelance PHP developer in Delhi to handle your database design and development, feel free to contact me. Let’s bring your project to life with robust and efficient database solutions!


This post combines technical insights with SEO-friendly keywords to ensure better visibility and engagement on your website. Let me know if you’d like further optimizations!

Note: if you have already created table then just add below code in default coilumn in PgAdmin table properties

nextval('registration.license_list_log_id_seq'::regclass) 
How to add multiple images into database using mysql and php

How to add multiple images into database using mysql and php

// start multiple image

$stmt = $conn->prepare(“INSERT INTO cat_images (img_url, cat_id) VALUES (?, ?)”);
$stmt->bind_param(“si”, $imagePath, $cat_id);
$uploadedImages = $_FILES[‘images’];

$cat_id = $conn->insert_id;

foreach ($uploadedImages[‘name’] as $key => $value) {
$targetDir = “main-images/galleries/”;
$fileName = basename($uploadedImages[‘name’][$key]);
$targetFilePath = $targetDir . $fileName;
if (file_exists($targetFilePath)) {
echo “Sorry, file already exists.<br>”;
} else {
if (move_uploaded_file($uploadedImages[“tmp_name”][$key], $targetFilePath)) {
$imagePath = $targetFilePath;
$stmt->execute();
echo “The file ” . $fileName . ” has been uploaded successfully.<br>”;
} else {
echo “Sorry, there was an error uploading your file.<br>”;
}
}
}
$stmt->close();
$conn->close();

// end multiple image

How to get the value of selected radio button using jQuery

Just use below code and modified according to your need.

Note: this is very useful for COD and Prepaid charge addition using javascript, jquery, PHP

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>


<br><br><br>
<script>
    $(document).ready(function(){
        $("input[type='radio']").change(function(){
        	var radioValue = $("input[name='payment_method']:checked").val();
            if(radioValue){
                alert("Your are a - " + radioValue);


                	var totl     = parseInt($("#total_amount").val());

		       	var shipping_value = totl ;
		          
		          // alert(pay_method);
		          // console.log(pay_method);

		          if(radioValue !=0)
		               {
		                    $("#pay").hide();

		               		let cod_charge = 50;

		               		var totl = totl + cod_charge;


		                   $("#gttotal").html("<label>Total Amount</label> <input type='text' name='total_amount' value='"+totl+"' readonly>");
		               }

		               

		               else
		               {
		               		$("#gttotal").html("<label>Total Amount</label> <input type='text' name='total_amount' value='"+totl+"' readonly>");
		               }




            }
        });
    });
</script>

<form action="forms.php">
    <h4>Please select your Payment Method.</h4>
    <p> 
        <label><input type="radio" name="payment_method" value="0" checked>Prepaid</label>
        <label><input type="radio" name="payment_method" value="1">COD</label> 
    </p>
   
    <div id="pay">
				<label>Total Amount</label>
				<input type="text" id="total_amount"  name='total_amount'  value="100" readonly>

		</div>

		<div id="gttotal"></div>

	<input type="submit" name="">


</form>


AWS

Steps:

AWS

putty
ubuntu

sudo su

apt update

apt install apache2

service apache2 start

service apache2 status

you will see a ubuntu on your ip

(/var/www/html/index.html)

cd /var/www/html/

ls

now you see index.html

now remove this index.html file

rm index.html

ls

install PHP

apt install php

install mysql sever

apt install mysql-server

now open filezilla

use ssh
and username ubuntu

password ppk key

upload file (in my case index2.zip) inside ubuntu folder

now move uploaded zip file into /var/www/html/

mv index2.zip /var/www/html/

cd /var/www/html/

ls
you can see your file here

now install unzip

apt install unzip

now unzip your file

unzip index2.zip

now
cd /etc/apache2/sites-available/

ls

now open
nano 000-default.conf

add your directory name if you have then save

now open mysql

mysql h localhost -u root

now change your db password using below query

ALTER USER ‘root’@localhost’ IDENTIFIED BY ‘BasantMallick’;

here BasantMallick is your password

now login with new password in mysql

now
create database frmscui;

use frmscui;

for importing sql file use below command

first exit from mysql

second move into parent or index file directory

and use below command

mysql -h localhost -u root -p yourdatabase > sqlfilename.sql

then again login into database

after login

use databasename

show tables

Note: for editing in file use nano before filename

Method 2:

Aws Cloud – host php mysql website on aws ec2 in hindi | http to https aws | free ssl

— * Used Commands *–

  1. update apt
    sudo apt-get update
  2. install mysql
    sudo apt-get install mysql-server
  3. mysql secure installation
    sudo mysql_secure_installation
  4. install apache
    sudo apt-get install apache2
  5. install php
    sudo apt-get install php libapache2-mod-php
  6. restart apache
    sudo systemctl restart apache2
  7. install phpmyadmin
    sudo apt-get install phpmyadmin php-mbstring php-gettext
  8. fix if php myadmin not work
    sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
    sudo a2enconf phpmyadmin.conf
    sudo systemctl restart apache2
  9. enable file permission
    sudo chown ubuntu /var/www/html
  10. change phpmyadmin password
    ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘new_password’;

Note: https://help.ubuntu.com/community/FilePermissions

ubuntu@ip-172-31-13-220:~$ sudo chown -R www-data:www-data Netrika/

ubuntu@ip-172-31-13-220:~$ ls -ilah

How to Display Fields in a Single Column on Mobile – WPForms

Certainly! If you want to convert a multi-column form layout to a single column when viewed on mobile, follow these steps using WPForms:

  1. Creating a Multi-Column Form Layout:
    • Start by creating a form with multiple columns. For example, let’s create a two-column layout using the CSS class wpforms-one-half.
    • The first field in each row should also use the wpforms-first class to indicate that it starts a new row.
  2. Displaying Fields in a Single Column on Mobile:
    • In the form builder, click on a field to display the Field Options.
    • Under the Advanced section, add the wpforms-mobile-full class to the CSS Classes field.
    • Repeat this for other fields in the form.
    • Don’t forget to click the Save button to keep the changes.

Now, when mobile visitors access your form, the multi-column layout will be shown as a single column. Your forms will look professional and user-friendly on smaller screens! 📱

Secured By miniOrange