Tuesday, 15 October 2024

Delete row using Mysqli

 Hi all,

Use this code

...............................

<?php


include('dbconnect.php');


// Use prepared statements to avoid SQL injection

$query = "delete FROM tbl_patient where id='$_GET[id]'";

mysqli_query($con, $query);

header('location:viewdoctor.php');



?>

View table using Mysqli

 Hi all


Use this code

-----------------------

<?php

include('dbconnect.php');


// Use prepared statements to avoid SQL injection

$query = 'SELECT * FROM tbl_patient';

$result = mysqli_query($con, $query); // mysqli_query replaces mysql_query


if (!$result) {

    $message = 'ERROR: ' . mysqli_error($con); // mysqli_error replaces mysql_error

    echo $message;

    return;

} else {

    echo '

    <html>

    <head>

        <style>

            table {

                width: 80%;

                border-collapse: collapse;

                margin: 50px auto;

                font-family: Arial, sans-serif;

                background-color: #f2f2f2;

            }

            th, td {

                border: 1px solid #ddd;

                padding: 12px;

                text-align: center;

            }

            th {

                background-color: #4CAF50;

                color: white;

            }

            tr:nth-child(even) {

                background-color: #f9f9f9;

            }

            tr:hover {

                background-color: #d1e0e0;

            }

            a {

                color: red;

                text-decoration: none;

            }

            a:hover {

                text-decoration: underline;

            }

        </style>

    </head>

    <body>

        <table>

            <tr>';


    // Fetch field names dynamically and create table headers

    $fields = mysqli_fetch_fields($result); // mysqli_fetch_fields replaces mysql_fetch_field

    foreach ($fields as $field) {

        echo '<th>' . ucfirst($field->name) . '</th>';

    }

    echo '<th>Delete</th></tr>';


    // Fetch table rows

    while ($row = mysqli_fetch_row($result)) { // mysqli_fetch_row replaces mysql_fetch_row

        echo '<tr>';

        $idval = $row[0]; // Assume the first column is the id

        foreach ($row as $cell) {

            echo '<td>' . htmlspecialchars($cell) . '</td>'; // Use htmlspecialchars to prevent XSS

        }

        echo '<td><a href="delpatient.php?id=' . $idval . '">Delete</a></td>';

        echo '</tr>';

    }


    echo '</table>

    </body>

    </html>';


    mysqli_free_result($result); // mysqli_free_result replaces mysql_free_result

}


mysqli_close($con); // mysqli_close replaces mysql_close

?>


Wednesday, 12 April 2023

Apriori Algorithm

 import numpy as nm

import matplotlib.pyplot as mtp  
import pandas as pd 
from apyori import apriori  
import urllib.request

url="http://localhost/web/hupaddpairs.php?item1="

dataset = pd.read_csv('item_set1.csv')  
transactions=[]  
for i in range(0, 32):
    transactions.append([str(dataset.values[i,j])  for j in range(0,5)]) 

vals=""
rules= apriori(transactions= transactions, min_support=0.003, min_confidence = 0.2, min_lift=3, min_length=2, max_length=2) 
results= list(rules)  
for item in results:
    pair = item[0]   
    items = [x for x in pair]  
    print("Rule: " + items[0] + " -> " + items[1])  
    print("Support: " + str(item[1]))  
    print("Confidence: " + str(item[2][0][2]))  
    print("Lift: " + str(item[2][0][3]))  
    print("=====================================")  
    vals=url+items[0]+"&item2="+items[1]
    print(vals)
    webUrl = urllib.request.urlopen(vals)
    vals=""

-------------------
Data
item_set1.csv

electronics.smartphone,	electronics.video.tv			
electronics.smartphone,	electronics.video.tv,appliances.kitchen.washer		
electronics.smartphone,	electronics.audio.headphone			
electronics.audio.headphone,electronics.smartphone	appliances.environment.vacuum,kids.skates	

Tuesday, 13 December 2022

PHP and MySQL

 

MySql

Mysql is a powerful RDBMS.

Top companies in the world such as Youtube, Paypal, Linkedin, Facebook, Twitter, Cisco, Uber, Verizon, Github, Walmart, Flipcart, Alibaba, Paypal etc have adopted Mysql for this reason.

PHP programming language has built-in APIs for interacting with MySQL.

MySQL is free and open-source software under the terms of the GNU General Public License, and is also available under a variety of proprietary licenses.

MySQL has stand-alone clients that allow users to interact directly with a MySQL database using SQL, but more often, MySQL is used with other programs to implement applications that need relational database capability. MySQL is a component of the LAMP web application software stack (and others), which is an acronym for Linux, Apache, MySQL, Perl/PHP/Python.

PHP General Points

 

PHP

Front End of the application is developed using PHP.

With the help of PHP static part of the project could be easily bind with Back End.

Login sessions can be easily managed with $_SESSION variables.

As this is free software the same can be downloaded and deployed easily.

It is integrated with a number of Common databases, including PostgreSQL , MySQL, , Sybase, Informix, and Microsoft SQL Server.

PHP supports a large number of important protocols such as IMAP ,POP3,  and LDAP.

PHP can handle forms, i.e. gather data from files,  save in hard drive etc.

We  add, delete, modify elements within our database using PHP.

 We can easily handle cookies variables and set cookies.

Using PHP, you can restrict users to access some pages of your website using session.

 It can encrypt data using various algorithms. Hashing can also be done.


Wednesday, 27 April 2022

Auto ID in forms

 Hi all,

This has got three parts

1. Code in the form - saveform.php

<html>

<body>

<?php

include('dbconnect.php');

$mid=getid('student','sid');

?>

<form action=savestudent.php method=post>

Id <input type=text name=id1 value='<?php echo $mid; ?>' disabled >

<input type=hidden name=id value='<?php echo $mid; ?>'  ><br>

Name <input type=text name=name><br>

<input type=submit value='save'>

</form>

</body>

</html>


2. Code in the save part -savestudent.php



<?php

$id=$_POST['id'];

echo $id;

include('dbconnect.php')

//DB insert query part

?>


3. Include file - dbconnect.php


<?php

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("anganwadi", $con);

function getid($tablename,$fieldid)

{

$query="select max($fieldid)+1 as mid from $tablename";

echo $query;

$data=mysql_query($query);

$maxid=0;

while($row=mysql_fetch_array($data))

{

$maxid=$row['mid'];

}

return $maxid;

}

?>

Thursday, 8 April 2021

Refresh a page continually and retrieve from db

 Hi all

Use settimeout function with php

Use this code on top of your program.

<script>setTimeout(hup, 3000);

function hup()

{

location.href='predictions.php';

}

</script>