Jump to content

Jonh_A84

New Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by Jonh_A84

  1. the project was working until i add date and time
    i just add date and time everywhere and everything is working (add , delete , view ) only update is not working and get this
    error Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id = ?' at line 1 in C:\xampp\htdocs\todolist\update.php:53 Stack trace: #0 C:\xampp\htdocs\todolist\update.php(53): mysqli_prepare(Object(mysqli), ' UPDATE list SE...') #1 {main} thrown in C:\xampp\htdocs\todolist\update.php on line 53

    i create the db at the beginning and again its not working (only update.php)

     

    db.PNG

  2. When i use mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

    Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id = ?' at line 1 in C:\xampp\htdocs\todolist\update.php:53 Stack trace: #0 C:\xampp\htdocs\todolist\update.php(53): mysqli_prepare(Object(mysqli), ' UPDATE list SE...') #1 {main} thrown in C:\xampp\htdocs\todolist\update.php on line 53

  3. update.php

    <?php
    // Include config file
    require_once "config.php";
     
    // Define variables and initialize with empty values
    $head = $content = $date = $time = "";
    $head_err = $content_err = $date_err = $time_err = "";
     
    // Processing form data when form is submitted
    if(isset($_POST["id"]) && !empty($_POST["id"])){
        // Get hidden input value
        $id = $_POST["id"];
        
        // Validate head
        $input_head = trim($_POST["head"]);
        if( strlen($input_head) > 200){
            $head_err = "Max character length is 200.";
        } elseif(!filter_var($input_head, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){
            $head_err = "Please enter a valid head.";
        } else{
            $head = $input_head;
        }
        
         // Validate content
        $input_content = trim($_POST["content"]);
        if(empty($input_content)){
            $content_err = "Please enter an content.";     
        } else{
            $content = $input_content;
        }
    	
    	 // Validate date
        $input_date = trim($_POST["date"]);
        if(empty($input_date)){
            $date_err = "Please enter an date.";     
        } else{
            $date = $input_date;
        }
    	
    	 // Validate time
        $input_time = trim($_POST["time"]);
        if(empty($input_time)){
            $time_err = "Please enter an time.";     
        } else{
            $time = $input_time;
        }
        
        // Check input errors before inserting in database
        if(empty($head_err) && empty($content_err) && empty($date_err) && empty($time_err)){
            // Prepare an update statement
            $sql = "UPDATE list SET head=?, content=?, date=?, time=?, WHERE id=?";
             
            if($stmt = mysqli_prepare($link, $sql)){
                // Bind variables to the prepared statement as parameters
                mysqli_stmt_bind_param($stmt, "ssssi", $param_head, $param_content, $param_date, $param_time, $param_id);
                
                // Set parameters
                $param_head = $head;
                $param_content = $content;
                $param_date = $date;
    			$param_time = $time;
                $param_id = $id;
                
                // Attempt to execute the prepared statement
                if(mysqli_stmt_execute($stmt)){
                    // Records updated successfully. Redirect to landing page
                    header("location: index.php");
                    exit();
                } else{
                    echo "Something went wrong. Please try again later.";
                }
            }
             
            // Close statement
            mysqli_stmt_close($stmt);
        }
        
        // Close connection
        mysqli_close($link);
    } else{
        // Check existence of id parameter before processing further
        if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
            // Get URL parameter
            $id =  trim($_GET["id"]);
            
            // Prepare a select statement
            $sql = "SELECT * FROM list WHERE id = ?";
            if($stmt = mysqli_prepare($link, $sql)){
                // Bind variables to the prepared statement as parameters
                mysqli_stmt_bind_param($stmt, "i", $param_id);
                
                // Set parameters
                $param_id = $id;
                
                // Attempt to execute the prepared statement
                if(mysqli_stmt_execute($stmt)){
                    $result = mysqli_stmt_get_result($stmt);
        
                    if(mysqli_num_rows($result) == 1){
                        /* Fetch result row as an associative array. Since the result set
                        contains only one row, we don't need to use while loop */
                        $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
                        
                        // Retrieve individual field value
                        $head = $row["head"];
                        $content = $row["content"];
                        $date = $row["date"];
    					$time = $row["time"];
                    } else{
                        // URL doesn't contain valid id. Redirect to error page
                        header("location: error.php");
                        exit();
                    }
                    
                } else{
                    echo "Oops! Something went wrong. Please try again later.";
                }
            }
            
            // Close statement
            mysqli_stmt_close($stmt);
            
            // Close connection
            mysqli_close($link);
        }  else{
            // URL doesn't contain id parameter. Redirect to error page
            header("location: error.php");
            exit();
        }
    }
    ?>
     
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Update Record</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
    	    <link rel="icon" type="image/png" href="https://www.htmlhints.com/image/fav-icon.png">
        <meta name="msvalidate.01" content="B7807734CA7AACC0779B341BBB766A4E" />
        <meta name="p:domain_verify" content="78ad0b4e41a4f27490d91585cb10df4a"/>
        <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
        <!-- Global site tag (gtag.js) - Google Analytics -->
        <script async src="https://www.googletagmanager.com/gtag/js?id=UA-145078782-1"></script>
        <script>
          window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());
        
          gtag('config', 'UA-145078782-1');
        </script>
    
            <style>
                        .wrapper{
                width: 500px;
                margin: 0 auto;
            }
        .hh_button {
        display: inline-block;
        text-decoration: none;
        background: linear-gradient(to right,#ff8a00,#da1b60);
        border: none;
        color: white;
        padding: 10px 25px;
        font-size: 1rem;
        border-radius: 3px;
        cursor: pointer;
        font-family: 'Roboto', sans-serif;
        position: relative;
        margin-top: 30px;
        margin: 0px;
        position: absolute;
        right: 20px;
        top: 1.5%;
        }
        header {
        color: white;
        padding: 20px;
        margin-bottom: 20px;
        }
        header a,  header a:hover {
            text-decoration: none;
            color: white;
        }
        </style>
    </head>
    <body>
                <header>
            <strong><i class="fas fa-chevron-left"></i> <a href="https://www.htmlhints.com/"></a> <i class="fas fa-chevron-right"></i></strong>
           
          </header>
        <div class="wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-header">
                            <h2>Update Record</h2>
                        </div>
                        <p>Please edit the input values and submit to update the record.</p>
                        <form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
                            <div class="form-group <?php echo (!empty($head_err)) ? 'has-error' : ''; ?>">
                                <label>head</label>
                                <input type="text" name="head" class="form-control" value="<?php echo $head; ?>">
                                <span class="help-block"><?php echo $head_err;?></span>
                            </div>
                            <div class="form-group <?php echo (!empty($content_err)) ? 'has-error' : ''; ?>">
                                <label>content</label>
                                <textarea name="content" class="form-control"><?php echo $content; ?></textarea>
                                <span class="help-block"><?php echo $content_err;?></span>
                            </div>
                           <div class="form-group <?php echo (!empty($date_err)) ? 'has-error' : ''; ?>">
                                <label>date</label>
                                <input type="date" name="date" class="form-control" value="<?php echo $date; ?>">
                                <span class="help-block"><?php echo $date_err;?></span>
                            </div>
    						<div class="form-group <?php echo (!empty($time_err)) ? 'has-error' : ''; ?>">
                                <label>time</label>
                                <input type="time" name="time" class="form-control" value="<?php echo $time; ?>">
                                <span class="help-block"><?php echo $time_err;?></span>
                            </div>
                            </div>
                            <input type="hidden" name="id" value="<?php echo $id; ?>"/>
                            <input type="submit" class="btn btn-primary" value="Submit">
                            <a href="index.php" class="btn btn-default">Cancel</a>
                        </form>
                    </div>
                </div>        
            </div>
        </div>
        <ins class="adsbygoogle my-3"
    style="display:block"
    data-ad-format="fluid"
    data-ad-layout-key="-fb+5w+4e-db+86"
    data-ad-client="ca-pub-1506739985879215"
    data-ad-slot="5016195832"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    </body>
    </html>

    database.sql

    -- phpMyAdmin SQL Dump
    -- version 5.0.3
    -- https://www.phpmyadmin.net/
    --
    -- Host: 127.0.0.1
    -- Generation Time: Nov 19, 2020 at 09:41 PM
    -- Server version: 10.4.14-MariaDB
    -- PHP Version: 7.4.11
    
    SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
    START TRANSACTION;
    SET time_zone = "+00:00";
    
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8mb4 */;
    
    --
    -- Database: `tododb`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `list`
    --
    
    CREATE TABLE `list` (
      `id` int(20) NOT NULL,
      `head` varchar(200) NOT NULL,
      `content` text NOT NULL,
      `date` date NOT NULL,
      `time` time NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `list`
    --
    
    INSERT INTO `list` (`id`, `head`, `content`, `date`, `time`) VALUES
    (69, 'task', 'test123', '2222-12-13', '22:22:00');
    
    --
    -- Indexes for dumped tables
    --
    
    --
    -- Indexes for table `list`
    --
    ALTER TABLE `list`
      ADD PRIMARY KEY (`id`);
    
    --
    -- AUTO_INCREMENT for dumped tables
    --
    
    --
    -- AUTO_INCREMENT for table `list`
    --
    ALTER TABLE `list`
      MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=70;
    COMMIT;
    
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

     

    Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, bool given in C:\xampp\htdocs\todolist\update.php on line 75

  4. database -todolist.sql

    -- phpMyAdmin SQL Dump
    -- version 5.0.3
    -- https://www.phpmyadmin.net/
    --
    -- Host: 127.0.0.1
    -- Generation Time: Nov 19, 2020 at 07:27 PM
    -- Server version: 10.4.14-MariaDB
    -- PHP Version: 7.4.11
    
    SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
    START TRANSACTION;
    SET time_zone = "+00:00";
    
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8mb4 */;
    
    --
    -- Database: `list`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `todolist`
    --
    
    CREATE TABLE `todolist` (
      `id` int(10) NOT NULL,
      `head` varchar(200) NOT NULL,
      `content` text NOT NULL,
      `date` int(11) NOT NULL,
      `time` int(11) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
    
    --
    -- Indexes for dumped tables
    --
    
    --
    -- Indexes for table `todolist`
    --
    ALTER TABLE `todolist`
      ADD PRIMARY KEY (`id`);
    
    --
    -- AUTO_INCREMENT for dumped tables
    --
    
    --
    -- AUTO_INCREMENT for table `todolist`
    --
    ALTER TABLE `todolist`
      MODIFY `id` int(10) NOT NULL AUTO_INCREMENT;
    COMMIT;
    
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

    config.php

    <?php
    /* Database credentials. Assuming you are running MySQL
    server with default setting (user 'root' with no password) */
    define('DB_SERVER', 'localhost');
    define('DB_USERNAME', 'root');
    define('DB_PASSWORD', '');
    define('DB_NAME', 'list');
     
    /* Attempt to connect to MySQL database */
    $mysqli = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
     
    // Check connection
    if($mysqli === false){
        die("ERROR: Could not connect. " . $mysqli->connect_error);
    }
    ?>

    create.php

    <?php
    // Include config file
    require_once 'config.php';
     
    // Define variables and initialize with empty values
    $head = $content = $date = $time= "";
    $head_err = $content_err = $date_err = $time_err = "";
     
    // Processing form data when form is submitted
    if($_SERVER["REQUEST_METHOD"] == "POST"){
        // Validate head
         $input_head = trim($_POST["head"]);
        if( strlen( $input_head) > 200){
            $head_err = "Max character length is 200.";
        } elseif(!filter_var($input_head, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){
            $head_err = "Please enter a valid head.";
        } else{
            $head = $input_head;
        }
        
       
        
        
        // Check input errors before inserting in database
        if(empty($head_err) ){
            // Prepare an insert statement
            $sql = "INSERT INTO employees (head, content, date,time) VALUES (?, ?, ?, ?)";
    
            if($stmt = $mysqli->prepare($sql)){
                // Bind variables to the prepared statement as parameters
                $stmt->bind_param("sss", $param_head, $param_content, $param_date, $param_time);
                
                // Set parameters
                $param_head = $head;
                $param_content = $content;
                $param_date = $date;
    			$param_time = $time;
                
                // Attempt to execute the prepared statement
                if($stmt->execute()){
                    // Records created successfully. Redirect to landing page
                    header("location: index.php");
                    exit();
                } else{
                    echo "Something went wrong. Please try again later.";
                }
            }
             
            // Close statement
            $stmt->close();
        }
        
        // Close connection
        $mysqli->close();
    }
    ?>
     
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Create ToDoList</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
        <style type="text/css">
            .wrapper{
                width: 500px;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div class="wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-header">
                            <h2>Create ToDoList</h2>
                        </div>
                        <p>Please fill this form and submit to add todolist record to the database.</p>
                        <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
                            <div class="form-group <?php echo (!empty($head_err)) ? 'has-error' : ''; ?>">
                                <label>Head</label>
                                <input type="text" name="head" class="form-control" value="<?php echo $head; ?>">
                                <span class="help-block"><?php echo $head_err;?></span>
                            </div>
                            <div class="form-group <?php echo (!empty($content_err)) ? 'has-error' : ''; ?>">
                                <label>Content</label>
                                <textarea name="content" class="form-control"><?php echo $content; ?></textarea>
                                <span class="help-block"><?php echo $content_err;?></span>
                            </div>
                            <div class="form-group <?php echo (!empty($date_err)) ? 'has-error' : ''; ?>">
                                <label>Date</label>
                                <input type="date" name="date" class="form-control" value="<?php echo $date; ?>">
                                <span class="help-block"><?php echo $date_err;?></span>
                            </div>
    						<div class="form-group <?php echo (!empty($time_err)) ? 'has-error' : ''; ?>">
                                <label>Time</label>
                                <input type="time" name="time" class="form-control" value="<?php echo $time; ?>">
                                <span class="help-block"><?php echo $time_err;?></span>
                            </div>
                            <input type="submit" class="btn btn-primary" value="Submit">
                            <a href="index.php" class="btn btn-default">Cancel</a>
                        </form>
                    </div>
                </div>        
            </div>
        </div>
    </body>
    </html>

    index.php

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Dashboard</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
        <style type="text/css">
            .wrapper{
                width: 650px;
                margin: 0 auto;
            }
            .page-header h2{
                margin-top: 0;
            }
            table tr td:last-child a{
                margin-right: 15px;
            }
        </style>
        <script type="text/javascript">
            $(document).ready(function(){
                $('[data-toggle="tooltip"]').tooltip();   
            });
        </script>
    </head>
    <body>
        <div class="wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-header clearfix">
                            <h2 class="pull-left">ToDoList</h2>
                            <a href="create.php" class="btn btn-success pull-right">Add New todolist</a>
                        </div>
                        <?php
                        // Include config file
                        require_once 'config.php';
                        
                        // Attempt select query execution
                        $sql = "SELECT * FROM todolist";
                        if($result = $mysqli->query($sql)){
                            if($result->num_rows > 0){
                                echo "<table class='table table-bordered table-striped'>";
                                    echo "<thead>";
                                        echo "<tr>";
                                            echo "<th>#</th>";
                                            echo "<th>head</th>";
                                            echo "<th>content</th>";
                                            echo "<th>date</th>";
    										  echo "<th>time</th>";
                                            echo "<th>Action</th>";
                                        echo "</tr>";
                                    echo "</thead>";
                                    echo "<tbody>";
                                    while($row = $result->fetch_array()){
                                        echo "<tr>";
                                            echo "<td>" . $row['id'] . "</td>";
                                            echo "<td>" . $row['head'] . "</td>";
                                            echo "<td>" . $row['content'] . "</td>";
                                            echo "<td>" . $row['date'] . "</td>";
    										echo "<td>" . $row['time'] . "</td>";
                                            echo "<td>";
                                                echo "<a href='read.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
                                                echo "<a href='update.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
                                                echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
                                            echo "</td>";
                                        echo "</tr>";
                                    }
                                    echo "</tbody>";                            
                                echo "</table>";
                                // Free result set
                                $result->free();
                            } else{
                                echo "<p class='lead'><em>No records were found.</em></p>";
                            }
                        } else{
                            echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
                        }
                        
                        // Close connection
                        $mysqli->close();
                        ?>
                    </div>
                </div>        
            </div>
        </div>
    </body>
    </html>

    update.php

    <?php
    // Include config file
    require_once 'config.php';
     
    // Define variables and initialize with empty values
    $head = $content = $date = $time = "";
    $head_err = $content_err = $date_err = salary = "";
     
    // Processing form data when form is submitted
    if(isset($_POST["id"]) && !empty($_POST["id"])){
        // Get hidden input value
        $id = $_POST["id"];
        
     // Validate head
         $input_head = trim($_POST["head"]);
        if( strlen( $input_head) > 200){
            $head_err = "Max character length is 200.";
        } elseif(!filter_var($input_head, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){
            $head_err = "Please enter a valid head.";
        } else{
            $head = $input_head;
        }
        
        
        
        // Check input errors before inserting in database
        if(empty($head_err)){
            // Prepare an insert statement
            $sql = "UPDATE employees SET head=?, content=?, date=?, time=? , WHERE id=?";
    
            if($stmt = $mysqli->prepare($sql)){
                // Bind variables to the prepared statement as parameters
                $stmt->bind_param("ssssi", $param_head, $param_content, $param_date, $param_time, $param_id);
                
                // Set parameters
                $param_head = $head;
                $param_content = $content;
                $param_date = $date;
    			$param_time = $time;
                $param_id = $id;
                
                // Attempt to execute the prepared statement
                if($stmt->execute()){
                    // Records updated successfully. Redirect to landing page
                    header("location: index.php");
                    exit();
                } else{
                    echo "Something went wrong. Please try again later.";
                }
            }
             
            // Close statement
            $stmt->close();
        }
        
        // Close connection
        $mysqli->close();
    } else{
        // Check existence of id parameter before processing further
        if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
            // Get URL parameter
            $id =  trim($_GET["id"]);
            
            // Prepare a select statement
            $sql = "SELECT * FROM todolist WHERE id = ?";
            if($stmt = $mysqli->prepare($sql)){
                // Bind variables to the prepared statement as parameters
                $stmt->bind_param("i", $param_id);
                
                // Set parameters
                $param_id = $id;
                
                // Attempt to execute the prepared statement
                if($stmt->execute()){
                    $result = $stmt->get_result();
                    
                    if($result->num_rows == 1){
                        /* Fetch result row as an associative array. Since the result set
                        contains only one row, we don't need to use while loop */
                        $row = $result->fetch_array(MYSQLI_ASSOC);
                        
                        // Retrieve individual field value
                        $head = $row["head"];
                        $content = $row["content"];
                        $date = $row["date"];
    					$time = $row["time"];
                    } else{
                        // URL doesn't contain valid id. Redirect to error page
                        header("location: error.php");
                        exit();
                    }
                    
                } else{
                    echo "Oops! Something went wrong. Please try again later.";
                }
            }
            
            // Close statement
            $stmt->close();
            
            // Close connection
            $mysqli->close();
        }  else{
            // URL doesn't contain id parameter. Redirect to error page
            header("location: error.php");
            exit();
        }
    }
    ?>
     
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Update todolist</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
        <style type="text/css">
            .wrapper{
                width: 500px;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div class="wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-header">
                            <h2>Update todolist</h2>
                        </div>
                        <p>Please edit the input values and submit to update the todolist.</p>
                        <form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
                            <div class="form-group <?php echo (!empty($head_err)) ? 'has-error' : ''; ?>">
                                <label>head</label>
                                <input type="text" name="head" class="form-control" value="<?php echo $head; ?>">
                                <span class="help-block"><?php echo $head_err;?></span>
                            </div>
                            <div class="form-group <?php echo (!empty($content_err)) ? 'has-error' : ''; ?>">
                                <label>content</label>
                                <textarea name="content" class="form-control"><?php echo $content; ?></textarea>
                                <span class="help-block"><?php echo $content_err;?></span>
                            </div>
                            <div class="form-group <?php echo (!empty($date_err)) ? 'has-error' : ''; ?>">
                                <label>data</label>
                                <input type="date" name="date" class="form-control" value="<?php echo $date; ?>">
                                <span class="help-block"><?php echo $date_err;?></span>
                            </div>
    						<div class="form-group <?php echo (!empty($date_err)) ? 'has-error' : ''; ?>">
                                <label>time</label>
                                <input type="time" name="time" class="form-control" value="<?php echo $time; ?>">
                                <span class="help-block"><?php echo $time_err;?></span>
                            </div>
                            <input type="hidden" name="id" value="<?php echo $id; ?>"/>
                            <input type="submit" class="btn btn-primary" value="Submit">
                            <a href="index.php" class="btn btn-default">Cancel</a>
                        </form>
                    </div>
                </div>        
            </div>
        </div>
    </body>
    </html>

    read.php

    <?php
    // Check existence of id parameter before processing further
    if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
        // Include config file
        require_once 'config.php';
        
        // Prepare a select statement
        $sql = "SELECT * FROM todolist WHERE id = ?";
        
        if($stmt = $mysqli->prepare($sql)){
            // Bind variables to the prepared statement as parameters
            $stmt->bind_param("i", $param_id);
            
            // Set parameters
            $param_id = trim($_GET["id"]);
            
            // Attempt to execute the prepared statement
            if($stmt->execute()){
                $result = $stmt->get_result();
                
                if($result->num_rows == 1){
                    /* Fetch result row as an associative array. Since the result set
                    contains only one row, we don't need to use while loop */
                    $row = $result->fetch_array(MYSQLI_ASSOC);
                    
                    // Retrieve individual field value
                    $head = $row["head"];
                    $content = $row["content"];
                    $date = $row["date"];
    				$time = $row["time"];
                } else{
                    // URL doesn't contain valid id parameter. Redirect to error page
                    header("location: error.php");
                    exit();
                }
                
            } else{
                echo "Oops! Something went wrong. Please try again later.";
            }
        }
         
        // Close statement
        $stmt->close();
        
        // Close connection
        $mysqli->close();
    } else{
        // URL doesn't contain id parameter. Redirect to error page
        header("location: error.php");
        exit();
    }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>View todolist</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
        <style type="text/css">
            .wrapper{
                width: 500px;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div class="wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-header">
                            <h1>View todolist</h1>
                        </div>
                        <div class="form-group">
                            <label>Head</label>
                            <p class="form-control-static"><?php echo $row["head"]; ?></p>
                        </div>
                        <div class="form-group">
                            <label>Content</label>
                            <p class="form-control-static"><?php echo $row["content"]; ?></p>
                        </div>
                        <div class="form-group">
                            <label>Date</label>
                            <p class="form-control-static"><?php echo $row["date"]; ?></p>
                        </div>
    					<div class="form-group">
                            <label>Time</label>
                            <p class="form-control-static"><?php echo $row["time"]; ?></p>
                        </div>
                        <p><a href="index.php" class="btn btn-primary">Back</a></p>
                    </div>
                </div>        
            </div>
        </div>
    </body>
    </html>

    delete.php

    <?php
    // Process delete operation after confirmation
    if(isset($_POST["id"]) && !empty($_POST["id"])){
        // Include config file
        require_once 'config.php';
        
        // Prepare a select statement
        $sql = "DELETE FROM todolist WHERE id = ?";
        
        if($stmt = $mysqli->prepare($sql)){
            // Bind variables to the prepared statement as parameters
            $stmt->bind_param("i", $param_id);
            
            // Set parameters
            $param_id = trim($_POST["id"]);
            
            // Attempt to execute the prepared statement
            if($stmt->execute()){
                // Records deleted successfully. Redirect to landing page
                header("location: index.php");
                exit();
            } else{
                echo "Oops! Something went wrong. Please try again later.";
            }
        }
         
        // Close statement
        $stmt->close();
        
        // Close connection
        $mysqli->close();
    } else{
        // Check existence of id parameter
        if(empty(trim($_GET["id"]))){
            // URL doesn't contain id parameter. Redirect to error page
            header("location: error.php");
            exit();
        }
    }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>View todolist</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
        <style type="text/css">
            .wrapper{
                width: 500px;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div class="wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-header">
                            <h1>Delete todolist</h1>
                        </div>
                        <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
                            <div class="alert alert-danger fade in">
                                <input type="hidden" name="id" value="<?php echo trim($_GET["id"]); ?>"/>
                                <p>Are you sure you want to delete this todolist?</p><br>
                                <p>
                                    <input type="submit" value="Yes" class="btn btn-danger">
                                    <a href="index.php" class="btn btn-default">No</a>
                                </p>
                            </div>
                        </form>
                    </div>
                </div>        
            </div>
        </div>
    </body>
    </html>

    error.php

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Error</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
        <style type="text/css">
            .wrapper{
                width: 750px;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div class="wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-header">
                            <h1>Invalid Request</h1>
                        </div>
                        <div class="alert alert-danger fade in">
                            <p>Sorry, you've made an invalid request. Please <a href="index.php" class="alert-link">go back</a> and try again.</p>
                        </div>
                    </div>
                </div>        
            </div>
        </div>
    </body>
    </html>

    This is the code of all the program 

    This is the ERROR
    Fatal error: Uncaught Error: Call to a member function close() on bool in C:\xampp\htdocs\prject\create.php:50 Stack trace: #0 {main} thrown in C:\xampp\htdocs\project\create.php on line 50

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.