Database - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Database.php
- <!DOCTYPE html>
- <html>
- <body>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- JobID: <input type="int" name="id"><br>
- Title: <input type="text" name="name"><br>
- Description: <input type="text" name="description"><br>
- Date: <input type="text" name="Date"><br>
- <input type="submit"><br>
- </form>
- <?php
- // Your code here!
- $servername = "localhost";
- $username = "username";
- $password = "password";
- $conn = new mysqli($servername,$username,$password);
- if (mysqli_connect_error()){
- die("Connection Failed: ".mysqli_connect_error());
- }
- if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
- echo "We don't have mysqli!!!";
- $sql="CREATE DATABASE PNM";
- if($conn->query($sql)=== TRUE){
- echo "Database Created";
- }
- else{
- echo "Error Creating Database";
- $conn->error;
- }
- $conn = new mysqli($servername,$username,$password,$sql);
- if (mysqli_connect_error()){
- die("Connection: ".mysqli_connect_error());
- }
- $table1 = "CREATE TABLE jobs(JobID INT(6) UNSIGNED PRIMARY KEY,
- Title VARCHAR(45) NOT NULL, Description VARCHAR(255) NOT NULL,
- JobDate DATE(11) NOT NULL";
- if($conn->query($table1) === TRUE){
- echo "Table Created";
- }
- else{
- echo "Error Creating Table: ".$conn->error;
- }
- $values = "Insert Into jobs(JobID,Title,Description,JobDate)
- VALUES (?.?.?.?)";
- $stmt -> bind_param("issb",$jobId,$jobTitle,$jobDescription,$date);
- $jobId = $_POST["id"];
- $jobTitle = $_POST["name"];
- $jobDescription = $_POST["description"];
- $date = $_POST["JobDate"];
- $stmt->execute();
- if(mysqli_query($conn,$values)){
- echo "New record added";
- }
- else{
- echo "Error ".$values. "<br>" .mysqli_error($conn);
- }
- mysqli_close();
- ?>
- </body>
- </html>
File Description
- Database
- PHP Code
- 07 Aug-2019
- 1.75 Kb
You can Share it:
Latest PHP Pastes