diff --git a/README.md b/README.md index ca9d321..c597f1b 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 " + + + + + +"; +while($row=$result->fetch_assoc()) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; +} +echo "
NamePhoneEmail
" . $row['name'] . "" . $row['phone'] . "" . $row['email'] . "
"; +$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

+ + +
+
+
+

All Records

+
+ query($sql); + if($result) { + if($result->num_rows>0) + { + echo "" . + ""; + while($row=$result->fetch_assoc()) + { + echo ""; + } + echo "
NamePhoneEmail
".$row["name"]. + "".$row["phone"]. + "".$row["email"]. + "
"; + } + 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 "" . + ""; + while($row=$result->fetch_assoc()) + { + echo ""; + } + echo "
NamePhoneEmail
".$row["name"]."".$row["phone"]."".$row["email"]."
"; + } + else { + echo "There is no record with the name ".$name; + } + } + else { + echo "There is no record with the name ".$name; + } + + ?> +
+
+ +
+