Today, We want to share with you Add Session Array programming with php.
In this post we will show you PHP Add to Session Array, hear for How to create, retrieve and delete session arrays in PHP we will give you demo and example for implement.In this post, we will learn about PHP – How To Add Session Array with an example.
Add Session Array programming with php
There are the Following The simple About Add Session Array programming with php Full Information With Example and source code with how to learn web development on your own.
Making The Interface
index.php
<!DOCTYPE html> <?php session_start(); ?> <html lang="en"> <head> <title></title> <meta charset="UTF-8" name="viewport" content="width=device-wdith, initial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <a class="navbar-brand" href="https://www.pakainfo.com/add-session-array-programming/%3Ca%20href=">Pakainfo</a> </a> </div> </nav> <div class="pakainfo col-md-3"></div> <div class="pakainfo col-md-6 well"> <h3 class="text-primary">PHP - How To Add Session Array</h3> <hr style="border-top:1px dotted #3d3d3d;"/> <button class="btn btn-success" data-toggle="modal" data-target="#form_modal"><span class="glyphicon glyphicon-plus"></span> Add Data</button> <br /><br /> <table class="table table-bordered"> <thead class="alert-info"> <tr> <th>studentFname</th> <th>studentLname</th> <th>studentAddress</th> </tr> </thead> <tbody style="background-color:#ffffff;"> <?php if(ISSET($_SESSION['student'])){ foreach($_SESSION['student'] as $key => $value){ ?> <tr> <td><?php echo $value['studentfname']?></td> <td><?php echo $value['studentlname']?></td> <td><?php echo $value['studentaddress']?></td> </tr> <?php } } ?> </tbody> </table> </div> <div class="modal fade" id="form_modal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog" role="document"> <form action="save.php" method="POST"> <div class="modal-content"> <div class="modal-body"> <div class="col-md-2"></div> <div class="col-md-8"> <div class="form-group"> <label>studentFname</label> <input class="stud form-control" type="text" name="studentfname" required="required" /> </div> <div class="form-group"> <label>studentLname</label> <input class="stud form-control" type="text" name="studentlname" required="required" /> </div> <div class="form-group"> <label>studentAddress</label> <input class="stud form-control" type="text" name="studentaddress" required="required" /> </div> </div> </div> <div style="clear:both;"></div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-dismiss="modal"><span class="pakainfo glyphicon glyphicon-remove"></span> Close</button> <button name="save" class="btn btn-success"><span class="glyphicon glyphicon-save"></span> Save</button> </div> </div> </form> </div> </div> </body> <script src="https://www.pakainfo.com/js/jquery-3.2.1.min.js"></script> <script src="https://www.pakainfo.com/js/bootstrap.js"></script> </html>
Making the Main Function
save.php
<?php session_start(); if(ISSET($_POST['save'])){ if(ISSET($_SESSION['student'])){ $student = array( 'studentfname' => $_POST['studentfname'], 'studentlname' => $_POST['studentlname'], 'studentaddress' => $_POST['studentaddress'] ); $id = count($_SESSION['student']); $_SESSION['student'][$id] = $student; echo "<script>alert('Data Inserted')</script>"; echo "<script>window.location='index.php'</script>"; }else{ $student = array( 'studentfname' => $_POST['studentfname'], 'studentlname' => $_POST['studentlname'], 'studentaddress' => $_POST['studentaddress'] ); $_SESSION['student'][0] = $student; echo "<script>alert('Students Data Inserted')</script>"; echo "<script>window.location='index.php'</script>"; } } ?>
Multiple Image Upload in php with Database
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Session array in PHP adding or deleting elements.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.