Rumah >pembangunan bahagian belakang >tutorial php >HI,小弟我是一个PHP新手,今天一个有关问题折腾了一下午,请大家帮小弟我看一上,万分感谢

HI,小弟我是一个PHP新手,今天一个有关问题折腾了一下午,请大家帮小弟我看一上,万分感谢

WBOY
WBOYasal
2016-06-13 10:51:39777semak imbas

HI,我是一个PHP新手,今天一个问题折腾了一上午,请大家帮我看一下,万分感谢

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->    <title>Book-O-Rama Book Entry Results</title>    <style type="text/css">        </style>    <script type="text/javascript"></script>    <script>        </script>    <h1>Book-O-Rama Book Entry Result</h1>    <?php //create short variable names        $isbn = $_POST['isbn'];        $author = $_POST['author'];        $title = $_POST['title'];        $price = $_POST['price'];                if ( !$isbn || !$author || !$title || !$price ) {            echo "You have not entered all the required details.<br/>"."Please go back and try again.";            exit;        }        if ( !get_magic_quotes_gpc() ) {            $isbn = addslashes($isbn);            $author = addslashes($author);            $title = addslashes($title);            $price = doubleval($price);        }                @ $db = new mysqli('localhost', 'bookorama', 'bookorama123', 'books');        if ( mysqli_connect_errno() ) {            echo "Error: Could not connect to database. Please try again later.";            exit;        }                $query = "insert into books values ('$isbn', '$author', '$title', '$price')or die(mysql_error())";;                echo $query;                $result = $db->query($query);                if ( $result ) {            echo mysqli_affected_rows." book inserted into database.";        } else {            echo mysql_errno()."".mysql_error();            echo "An error has occurred.The item was not added.";        }                $db->close();            ?>


这是来自PHP和 MySQL web开发(第四版)中的一段代码。
我想问的是为什么最后总是输出An error has occurred.The item was not added
而且插入结果$result = -1 
请大家指点一下

------解决方案--------------------
$query = "insert into books values ('$isbn', '$author', '$title', '$price')";


echo $query;

$result = $db->query($query) or die($db->error);
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn