From 0d5a07f13fe04e3df20f83c8dba7d3a09d8e8bc6 Mon Sep 17 00:00:00 2001
From: Ramvardhan <42577719+Ram-the-coder@users.noreply.github.com>
Date: Tue, 2 Oct 2018 00:48:06 +0530
Subject: [PATCH 1/2] Add files via upload
---
README.md | 50 +++---------------------
connect.php | 15 ++++++++
create.php | 64 +++++++++++++++++++++++++++++++
delete.php | 19 ++++++++++
getuser.php | 40 ++++++++++++++++++++
index.php | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++
insert.php | 12 ++++++
select.php | 48 +++++++++++++++++++++++
8 files changed, 311 insertions(+), 44 deletions(-)
create mode 100644 connect.php
create mode 100644 create.php
create mode 100644 delete.php
create mode 100644 getuser.php
create mode 100644 index.php
create mode 100644 insert.php
create mode 100644 select.php
diff --git a/README.md b/README.md
index ca9d321..2d7350e 100644
--- a/README.md
+++ b/README.md
@@ -1,44 +1,6 @@
-# TEST
-
-## This test includes multiple stages
-
-## STAGE - 1
-
-1. Create a table name details under database details with columns name, phone, email.
-2. Create a php page called connect.php and write code to connect to the database.
-
-## STAGE - 2
-
-1. Create insert.php and include connect.php
-2. Insert 5 rows of data using php.
-
-## STAGE - 3
-
-1. Create select.php
-2. Select all data and print in a table format.
-3. Select particular data using name constraint and print in table format.
-
-## STAGE - 4
-
-1. Create delete.php
-2. Delete a row with email as a constraint.
-
-## STAGE - 5
-
-1. Create a webpage which includes buttons delete, insert, select.
-2. The respect pages and their functionality should be done on click of each button.
-
-## STAGE - 6
-
-1. Use ajax call to send and recieve data between the frontend and the backend.
-
-# Finally put a pull request to this repository once everything is done (also include the readme).
-
-
-## Questions asked
-
-1. Should we take data from user in task 2 to insert in table ?
-Ans : **YES**
-
-2. What is ajax call?
-Ans : Google it you will find it.
+#Ramvardhan - PHP Test Files
+
+- Go to index.php.
+- Even if you have no DB, it will prompt you and will create the DB and tables automatically.
+- Then you can add the records.
+- Ajax has been implemented to select the records when searching with name.
diff --git a/connect.php b/connect.php
new file mode 100644
index 0000000..95a8edc
--- /dev/null
+++ b/connect.php
@@ -0,0 +1,15 @@
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+}
+// echo "Connected successfully";
+?>
diff --git a/create.php b/create.php
new file mode 100644
index 0000000..e77d2d3
--- /dev/null
+++ b/create.php
@@ -0,0 +1,64 @@
+connect_error)
+{
+ die("Connection failed: " . $conn->connect_error);
+}
+
+// Create database
+$sql = "CREATE DATABASE ".$dbname;
+if ($conn->query($sql) === TRUE)
+{
+ echo "Database created successfully";
+}
+else
+{
+ echo ("");
+ echo "Error creating database: " . $conn->error;
+}
+$conn->close();
+
+//Create tables
+
+// Create connection
+$conn = new mysqli($servername, $username, $password, $dbname);
+if ($conn->connect_error)
+{
+ echo ("");
+ die("Connection failed: " . $conn->connect_error);
+}
+else {
+ $sql = "CREATE TABLE details(
+ name VARCHAR(50),
+ phone VARCHAR(15),
+ email VARCHAR(50)
+ )";
+ if ($conn->query($sql) === TRUE)
+ {
+ echo "Table created successfully";
+ echo ("");
+ }
+ else
+ {
+ echo ("");
+ echo "Error creating database: " . $conn->error;
+ }
+ $conn->close();
+}
+
+?>
diff --git a/delete.php b/delete.php
new file mode 100644
index 0000000..ff1fc69
--- /dev/null
+++ b/delete.php
@@ -0,0 +1,19 @@
+query($sql))
+{
+ echo ("");
+}
+else {
+ echo ("");
+}
+
+?>
diff --git a/getuser.php b/getuser.php
new file mode 100644
index 0000000..bc4eac5
--- /dev/null
+++ b/getuser.php
@@ -0,0 +1,40 @@
+
+
+
+ getuser.php
+
+
+
+
+
+
+
+
+
+
+
+query($sql);
+echo "
+
+Name
+Phone
+Email
+
+ ";
+while($row=$result->fetch_assoc()) {
+ echo "";
+ echo "" . $row['name'] . " ";
+ echo "" . $row['phone'] . " ";
+ echo "" . $row['email'] . " ";
+ echo "Delete ";
+ echo " ";
+}
+echo "
";
+$conn->close();
+?>
+
+
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..080addf
--- /dev/null
+++ b/index.php
@@ -0,0 +1,107 @@
+select_db($dbname);
+ $mysqli->close();
+ if(!$doesDBExist)
+ {
+ echo ("");
+ }
+?>
+
+
+
+ Stage-6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Records
+
Enter name to search:
+
+
+
+
+
All Records
+
+ query($sql);
+ if($result) {
+ if($result->num_rows>0)
+ {
+ echo "
" .
+ "Name Phone Email ";
+ while($row=$result->fetch_assoc())
+ {
+ echo "".$row["name"].
+ " ".$row["phone"].
+ " ".$row["email"].
+ " Delete ";
+ }
+ echo "
";
+ }
+ else {
+ echo "There are no records in the database";
+ }
+ }
+ else {
+ echo "There are no records in the database";
+ }
+ ?>
+
+
+
Enter values of new record to insert into database:
+
+
+
+
+
+
+
diff --git a/insert.php b/insert.php
new file mode 100644
index 0000000..8e2a2c9
--- /dev/null
+++ b/insert.php
@@ -0,0 +1,12 @@
+query($sql) === TRUE)
+ echo ("");
+?>
diff --git a/select.php b/select.php
new file mode 100644
index 0000000..64239f4
--- /dev/null
+++ b/select.php
@@ -0,0 +1,48 @@
+
+
+
+ details
+
+
+
+
+
+
+
+
+
+
+
+
+
Records Found:
+
+ query($sql);
+ if($result) {
+ if($result->num_rows>0)
+ {
+ echo "
" .
+ "Name Phone Email ";
+ while($row=$result->fetch_assoc())
+ {
+ echo "".$row["name"]." ".$row["phone"]." ".$row["email"]." ";
+ }
+ echo "
";
+ }
+ else {
+ echo "There is no record with the name ".$name;
+ }
+ }
+ else {
+ echo "There is no record with the name ".$name;
+ }
+
+ ?>
+
+
+
Go back
+
+
From cb32edf3af818029531032cc8f5b4e112767e24f Mon Sep 17 00:00:00 2001
From: Ramvardhan <42577719+Ram-the-coder@users.noreply.github.com>
Date: Tue, 2 Oct 2018 00:51:27 +0530
Subject: [PATCH 2/2] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 2d7350e..c597f1b 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-#Ramvardhan - PHP Test Files
+# Ramvardhan - PHP Test Files
- Go to index.php.
- Even if you have no DB, it will prompt you and will create the DB and tables automatically.