Friday, July 5, 2024
Thursday, April 20, 2023
Code to create Api key in PHP.
An API key is used by a lot of Web API to provide a form of access control. The key usually is linked to the identity of the API user as well as bundle of rights like a quota or areas of the APIs which are open for access to that key
Example::
<?php// get the HTTP method, path and body of the request$method = $_SERVER['REQUEST_METHOD'];$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));$input = json_decode(file_get_contents('php://input'),true);// connect to the mysql database$link = mysqli_connect('localhost', 'root', 'root', 'myDB');mysqli_set_charset($link,'utf8');// retrieve the table and key from the path$table = preg_replace('/[^a-z0-9_]+/i','',array_shift($request));$key = array_shift($request)+0;// escape the columns and values from the input object$columns = preg_replace('/[^a-z0-9_]+/i','',array_keys($input));$values = array_map(function ($value) use ($link) {if ($value===null) return null;return mysqli_real_escape_string($link,(string)$value);},array_values($input));// build the SET part of the SQL command$set = '';for ($i=0;$i<count($columns);$i++) {$set.=($i>0?',':'').'`'.$columns[$i].'`=';$set.=($values[$i]===null?'NULL':'"'.$values[$i].'"');}// create SQL based on HTTP methodswitch ($method) {case 'GET':$sql = "select * from `myform`".($key?" WHERE id=$key":''); break;case 'PUT':$sql = "update `myform` set $set where id=$key"; break;case 'POST':$sql = "insert into `myform` set $set"; break;case 'DELETE':$sql = "delete `myform` where id=$key"; break;}// excecute SQL statement$result = mysqli_query($link,$sql);// die if SQL statement failedif (!$result) {http_response_code(404);die(mysqli_error());}// print results, insert id or affected row countif ($method == 'GET') {if (!$key) echo '[';for ($i=0;$i<mysqli_num_rows($result);$i++) {echo ($i>0?',':'').json_encode(mysqli_fetch_object($result));}if (!$key) echo ']';} elseif ($method == 'POST') {echo mysqli_insert_id($link);} else {echo mysqli_affected_rows($link);}// close mysql connectionmysqli_close($link);?>
Tuesday, April 11, 2023
MYSQL Delete Query
If you want to delete a record from any MySQL table, then you can use the SQL command DELETE FROM. You can use this command at the mysql> prompt as well as in any script like PHP.
Syntax
DELETE FROM table_name [WHERE Clause]
- If the WHERE clause is not specified, then all the records will be deleted from the given MySQL table.
- You can specify any condition using the WHERE clause.
- You can delete records in a single table at a time.
Deleting Data Using a PHP Script
Example
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'DELETE FROM tutorials_tbl WHERE tutorial_id = 3';
mysql_select_db('TUTORIALS');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not delete data: ' . mysql_error());
}
echo "Deleted data successfully\n";
mysql_close($conn);
?>
Sunday, April 9, 2023
Update Data With MYSQL
There may be a requirement where the existing data in a MySQL table needs to be modified. You can do so by using the SQL UPDATE command. This will modify any field value of any MySQL table.
Syntax
SET column1=value, column2=value2,...
WHERE some_column=some_value
Updating Data Using a PHP Script
You can use the SQL UPDATE command with or without the WHERE CLAUSE into the PHP function – mysql_query(). This function will execute the SQL command in a similar way it is executed at the mysql> prompt.
Example
The following example to update the tutorial_title field for a record having tutorial_id as 3.<?php
$server = 'localhost';
$username = 'root';
$password = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'UPDATE tutorials_tbl
SET tutorial_title="Learning JAVA"
WHERE tutorial_id=3';
mysql_select_db('TUTORIALS');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
?>
Saturday, April 8, 2023
What PHP is?
PHP stands for Hypertext Preprocessor. PHP is a powerful and widely-used open source server-side scripting language to write dynamically generated web pages. PHP scripts are executed on the server and the result is sent to the browser as plain HTML.
PHP can be integrated with the number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
PHP can be embedded within a normal HTML web pages. That means inside your HTML documents you'll have PHP statements like this:
Example:
<!DOCTYPE HTML>
<html>
<head>
<title>PHP Application</title>
</head>
<body>
<?php
// Display greeting message
echo 'Hello World!';
?>
</body>
</html>
What You Can Do with PHP
There are lot more things you can do with PHP.
- You can generate dynamic pages and files.
- You can create, open, read, write and close files on the server.
- You can collect data from a web form such as user information, email, credit card information and much more.
- You can send emails to the users of your website.
- You can send and receive cookies to track the visitor of your website.
- You can store, delete, and modify information in your database.
- You can restrict unauthorized access to your website.
- You can encrypt data for safe transmission over internet.
Wednesday, April 5, 2023
How to Update Data MySQL?
There may be a requirement where the existing data in a MySQL table needs to be modified. You can do so by using the SQL UPDATE command. This will modify any field value of any MySQL table.
Syntax
UPDATE Syntax-
SET column1 = value1, column2 = value2, ...
WHERE condition;
Updating Data Using a PHP Script
Example
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'UPDATE tutorials_tbl SET tutorial_title="Learning JAVA" WHERE tutorial_id=3'
SET tutorial_title="Learning JAVA"
WHERE tutorial_id=3';
mysql_select_db('TUTORIALS');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
?>
Tuesday, April 4, 2023
What is MYSQL?
MySQL is a freely available open source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL).
SQL is the most popular language for adding, accessing and managing content in a database. It is most noted for its quick processing, proven reliability, ease and flexibility of use. MySQL is an essential part of almost every open source PHP application. Good examples for PHP & MySQL-based scripts are WordPress, Joomla, Magento and Drupal.
One of the most important things about using MySQL is to have a MySQL specialized host. Here are some of the things SiteGround can offer:
- MySQL is a database system used on the web
- MySQL is a database system that runs on a server
- MySQL is ideal for both small and large applications
- MySQL is very fast, reliable, and easy to use
- MySQL uses standard SQL
- MySQL compiles on a number of platforms
- MySQL is free to download and use
- MySQL is developed, distributed, and supported by Oracle Corporation
- MySQL is named after co-founder Monty Widenius's daughter: My
Database Connectivity
$servername = "localhost";
$username = "username";
$password = "password";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Friday, March 24, 2023
Best website hosting servers
Bluehost: This hosting server is popular among bloggers, small businesses, and WordPress users. It offers easy-to-use control panels, reliable uptime, and excellent customer support. https://www.bluehost.com/
HostGator: HostGator is a popular hosting server for small businesses, offering flexible plans, unlimited bandwidth, and 24/7 customer support. https://hotstar.com/
SiteGround: SiteGround is known for its fast loading speeds, excellent customer support, and user-friendly interface. It's a popular choice for WordPress sites and e-commerce stores. https://world.siteground.com/
A2 Hosting: A2 Hosting is a reliable hosting server with fast loading speeds, excellent uptime, and affordable pricing. It offers a variety of hosting plans, including shared, VPS, and dedicated hosting. https://www.a2hosting.com/
DreamHost: DreamHost is a reliable and user-friendly hosting server with a wide range of features and tools. It offers unlimited bandwidth and storage, free SSL certificates, and easy WordPress installation. https://www.dreamhost.com/
It's important to research and compares different hosting servers before choosing one that best suits your needs. Consider factors such as pricing, uptime, customer support, and features offered.
For Professional website contact WEB CODE ADDICT
View this post on Instagram A post shared by WebCodeAddict (@webcodeaddicted)
-
Web Design ,Logo Design, graphic design, website design: Web Design : encompasses many different skills and disciplines in the production a...
-
The Wedding is Responsive HTML theme for wedding planner websites. which helps you to build your own site. Wedding Planner theme has ...
-
<!doctype HTML> <html> <head> <meta content="text/html; charset=UTF-8" /> <title>Web Code Addict Ac...