コード例 #1
0
            if (!preg_match($isbn_pattern, $isbn)) {
                $errors[] = "ISBN non valido.";
            }
            if (filter_var($id_author, FILTER_VALIDATE_INT) === false) {
                $errors[] = "Autore non valido";
            }
            if (filter_var($pages, FILTER_VALIDATE_INT) === false || $pages < 1) {
                $errors[] = "Campo pagine non valido";
            }
            if (filter_var($price, FILTER_VALIDATE_FLOAT) === false || $price < 0.01) {
                $errors[] = "Prezzo non valido";
            }
            if (count($errors) == 0) {
                $price = number_format($price, 2);
                //Funzione che tronca a 2 cifre decimali...
                insertBook($title, $isbn, $id_author, $pages, $availability, $price);
            }
            break;
        default:
            break;
    }
}
?>
<div class="container">
	<h2> Aggiunta Libro </h2>
	<?php 
if (isset($errors)) {
    ?>
		<div class="errors">
			<?php 
    foreach ($errors as $error) {
コード例 #2
0
ファイル: index.php プロジェクト: silvereh/cs313-php
         include 'private/db_error.php';
     }
     break;
 case "insert_scripture":
     $name = filter_input(INPUT_POST, "book", FILTER_SANITIZE_STRING);
     $verse = filter_input(INPUT_POST, "verse", FILTER_VALIDATE_INT);
     $chapter = filter_input(INPUT_POST, "chapter", FILTER_VALIDATE_INT);
     $content = filter_input(INPUT_POST, "content", FILTER_SANITIZE_STRING);
     $new_topic = filter_input(INPUT_POST, "new_topic", FILTER_SANITIZE_STRING);
     $topic_names = filter_input(INPUT_POST, "topic_names", FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY);
     $new_topic_name = filter_input(INPUT_POST, "new_topic_name", FILTER_SANITIZE_STRING);
     require_once 'private/dbtest.php';
     require_once 'model/books.php';
     $book = getBookByName($name);
     while ($book === NULL) {
         $result = insertBook($name);
         if ($result != 1) {
             $book = getBookByName($name);
         }
     }
     require_once 'model/topics.php';
     if ($new_topic == "true") {
         insertTopic($new_topic_name);
         $topic_names[] = $new_topic_name;
     }
     foreach ($topic_names as $topic_name) {
         $topic = getTopicByName($topic_name);
         while ($topic === NULL) {
             $result = insertTopic($name);
             if ($result != 1) {
                 $topic = getTopicByName($name);