Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = "localhost";
- $user = "shinobi";
- $password ="";
- $database = "events";
- $id = "";
- $name = "";
- $clg = "";
- $evn = "";
- $email = "";
- $phone = "";
- mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
- // connect to mysql database
- try{
- $connect = mysqli_connect($host, $user, $password, $database);
- } catch (mysqli_sql_exception $ex) {
- echo 'Error';
- }
- // get values from the form
- function getPosts()
- {
- $posts = array();
- $posts[0] = $_POST['RegistrationID'];
- $posts[1] = $_POST['Name'];
- $posts[2] = $_POST['College'];
- $posts[3] = $_POST['Event'];
- $posts[4] = $_POST['Email'];
- $posts[5] = $_POST['Phone'];
- return $posts;
- }
- // Search
- if(isset($_POST['search']))
- {
- $data = getPosts();
- $search_Query = "SELECT * FROM eventable WHERE RegistrationID = $data[0]";
- $search_Result = mysqli_query($connect, $search_Query);
- if($search_Result)
- {
- if(mysqli_num_rows($search_Result))
- {
- while($row = mysqli_fetch_array($search_Result))
- {
- $id = $row['RegistrationID'];
- $name = $row['Name'];
- $clg = $row['College'];
- $evn = $row['Event'];
- $email = $row['Email'];
- $phone = $row['Phone'];
- }
- }else{
- echo 'No Data For This Id';
- }
- }else{
- echo 'Result Error';
- }
- }
- // Insert
- if(isset($_POST['insert']))
- {
- $data = getPosts();
- $insert_Query = "INSERT INTO eventable(Name,College,Event,Email,Phone) VALUES ('$data[1]','$data[2]','$data[3]','$data[4]','$data[5]');";
- try{
- $insert_Result = mysqli_query($connect, $insert_Query);
- if($insert_Result)
- {
- if(mysqli_affected_rows($connect) > 0)
- {
- echo 'Data Inserted';
- }else{
- echo 'Data Not Inserted';
- }
- }
- } catch (Exception $ex) {
- echo 'Error Insert '.$ex->getMessage();
- }
- }
- // Delete
- if(isset($_POST['delete']))
- {
- $data = getPosts();
- $delete_Query = "DELETE FROM eventable WHERE 'RegistrationID' = $data[0]";
- try{
- $delete_Result = mysqli_query($connect, $delete_Query);
- if($delete_Result)
- {
- if(mysqli_affected_rows($connect) > 0)
- {
- echo 'Data Deleted';
- }else{
- echo 'Data Not Deleted';
- }
- }
- } catch (Exception $ex) {
- echo 'Error Delete '.$ex->getMessage();
- }
- }
- // Edit
- if(isset($_POST['update']))
- {
- $data = getPosts();
- $update_Query = "UPDATE eventable SET 'Name'='$data[1]','College'='$data[2]','Event'=$data[3],'Email'=$data[4],'Phone'=$data[5] WHERE 'RegistrationID' = $data[0]";
- try{
- $update_Result = mysqli_query($connect, $update_Query);
- if($update_Result)
- {
- if(mysqli_affected_rows($connect) > 0)
- {
- echo 'Data Updated';
- }else{
- echo 'Data Not Updated';
- }
- }
- } catch (Exception $ex) {
- echo 'Error Update '.$ex->getMessage();
- }
- }
- ?>
- <!DOCTYPE Html>
- <html>
- <head>
- <title>PHP INSERT UPDATE DELETE SEARCH</title>
- </head>
- <body>
- <form action="proj.php" method="post">
- <input type="number" name="RegistrationID" placeholder="RegistrationID" value="<?php echo $id;?>"><br><br>
- <input type="text" name="Name" placeholder="Name" value="<?php echo $name;?>"><br><br>
- <input type="text" name="College" placeholder="College" value="<?php echo $clg;?>"><br><br>
- <input type="text" name="Event" placeholder="Event" value="<?php echo $evn;?>"><br><br>
- <input type="text" name="Email" placeholder="Email" value="<?php echo $email;?>"><br><br>
- <input type="number" name="Phone" placeholder="Phone" value="<?php echo $phone;?>"><br><br>
- <div>
- <!-- Input For Add Values To Database-->
- <input type="submit" name="insert" value="Add">
- <!-- Input For Edit Values -->
- <input type="submit" name="update" value="Update">
- <!-- Input For Clear Values -->
- <input type="submit" name="delete" value="Delete">
- <!-- Input For Find Values With The given ID -->
- <input type="submit" name="search" value="Find">
- </div>
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment