abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

6/10/2018

updating mysql data using php

hi in this session give detail about how update current data
for eg: name is mayur and actual in database kumar. for this purpose we use update query.
let us see,
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "employee";

// Create connection 

 $conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection 

  if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "UPDATE hello SET lastname='shahgadh' WHERE id=2";

if (mysqli_query($conn, $sql)) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . mysqli_error($conn);
}

mysqli_close($conn);
?>
in above example we see to update lastname whose id is 2 if it success then show message .
in case error pass mysqli_error in connection.

selecting data from mysql data using php

hi,
how to connect php to mysql & select data from mysql

<?php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "abcd";

// Create connection $conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT id, firstname, lastname FROM sample";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "no record found";
}

mysqli_close($conn);
?>



in the above shows that how pass connection in above example use mysqli_num_rows & mysqli_fetch_assoc to fetching result according yo number of rows & associated result.
in this use while loop to pass all associated columns. try above example comment if any

create mysql data using php

hi toady we are going to show how to create data using php
<?php
$servername = "localhost";
$username = "root";
$password = "hello";

// Create connection 

$conn = new mysqli($servername, $username, $password);
// Check connection

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Create database

$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
    echo "Database created successfully";
} else {
    echo "Error creating database: " . $conn->error;
}

$conn->close();
?>
in this session we learn how to create database using php in mysql it may localhost or serverhost
simply pass connection , call database, display message
 

use of MYSQL in PHP

HI,
main point in this session:
1. insert data
2. create data
3. select data
4. update data
5. delete data

1. insert data
<?php
$servername = "localhost";
$username = "abcd";
$password = "blank";
$dbname = "sample";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO hello(firstname, lastname, email)
VALUES ('mayur', 'kumar', 'kumar@kumar.com')";

if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

in the above example shows that mysqli connection pass & insert data into hello table of sample database.
if record inserted then show message about record inserted sucessfully.
remaining point we discuss in next session

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...