(Solved) : Please Code Need Add Input Data Sql Table Using Pdo Click Submit Want Get Message Data Add Q43958013 . . .
Please, I have this code below, I need to add the input data tothe SQL table by using (PDO) when click on submit, I want to get amessage “your data added successfully” and another button to showall saved data :
<html lang=”en”>
<head>
<meta charset=”utf-8″>
<title>Book Tilile</title>
<meta name=”description” content=”library”>
<meta name=”author” content=”5654.”>
<link rel=”stylesheet” href=”hjg.css”>
<?php
ini_set ( ‘display_errors’, 1 );
error_reporting ( E_ALL | E_STRICT );
?>
</head>
<body>
<?php
$bookTitle = $describtion = $price = $category = “”;
$bookTitleError = $describtionError = $priceError = $categoryError= “”;
$okay = true;
//bookTitle
if (isset ( $_GET [‘btnSubmit’] )) {
if (empty ( $_GET [‘bookTitle’] )) {
$bookTitleError = ‘Please, Book title should be filled!’;
$okay = FALSE;
} else {
$bookTitle = strip_tags ( ucfirst ( trim ( $_GET [‘bookTitle’] ) ));
}
//describtion
if (empty ( $_GET [‘describtion’] )) {
$describtionError = ‘Please provide a description!’;
$okay = FALSE;
} else {
$describtion = strip_tags ( ucfirst ( trim ( $_GET [‘describtion’]) ) );
}
//price
$price = strip_tags ( ucfirst ( trim ( $_GET [‘price’]) ) );
if (! is_numeric ( $price )) {
$priceError = “Price should be a positive number please, ” . $price. “, is not valid.”;
$okay = FALSE;
}
//category
if (empty ( $_GET [‘category’] )) {
$categoryError = ‘Please provide a category!’;
$okay = FALSE;
} else {
$category = strip_tags ( ucfirst ( trim ( $_GET [‘category’] ) ));
}
if (! $okay) {
print “<h1><span class=”error”> *** You have errorsin your data *** </span><h1>”;
}
print ” <h2> Book Summary <br></h2>”;
print ” Book Title:”.preg_replace(“/[^a-z0-9]/i”,””,$_GET[‘bookTitle’]).”<br/>”;
if($_GET[‘price’] <= 0) {
$priceError = “Price should be a positive number please, ” . $price. “, is not valid.”;
$okay = FALSE;
}else
print ” Price : “.filter_var( $_GET[‘price’],FILTER_SANITIZE_NUMBER_INT).”<br/>”;
print ” Describtion:”.preg_replace(“/[^a-z0-9]/i”,””,$_GET[‘describtion’]).”<br/>”;
print ” Category : $category <br> “;
}
?>
<form method=”get” name=”frmSticky”>
<p>
<label>Book Title: </label> <input type=”text”name=”bookTitle” size=”20″
<?php
if (isset ( $_GET [‘btnSubmit’] )) {
echo (“value = “” . $bookTitle . “” “);
}
?> /><span class=”error”> * <?php echo$bookTitleError;?></span>
</p>
<p>
<label> Describtion: </label> <textareaname=”describtion”>
<?php
if (isset ( $_GET [‘btnSubmit’] )) {
echo “$describtion “;
}
?></textarea>
<span class=”error”> * <?php echo $describtionError;?></span>
</p>
<p>
<label> Price: </label> <input name=”price”
<?php
if (isset ( $_GET [‘btnSubmit’] )) {
echo (“value = “” . $price . “” “);
}
?> /><span class=”error”> * <?php echo$priceError;?></span>
</p>
<label> Category: </label> <selectname=”category”>
<option> PHP database </option>
<option> Javascribt </option>
<option> Paython </option>
<?php
if (isset ( $_GET [‘btnSubmit’] )) {
echo (“value = “” . $category . “” “);
}
?> </select><span class=”error”> * <?php echo$categoryError;?></span>
<br><br>
<input type=”submit” name=”btnSubmit” value=”Submit”id=”submitButton”>
<button onclick=”window.location.href=’assignment1.php'”id=”reloadButton”>Reload
Form</button>
<br> <br>
</form>
use PDO SQL to save FORM data and show the tabel
so, I have to create SQL table “book title,description, price, category, then when the user input data in thathtml form that will save in sql tabel by using PDO connections phpwith SQL and message will appear (your data added successfully) andanother button to print the SQL table.
Expert Answer
Answer to Please, I have this code below, I need to add the input data to the SQL table by using (PDO) when click on submit, I wan…
OR