mysql 数据库 表单
PHP入门,在尝试编写一个图书数据库,数据库写入有一些问题总界面模块
<!DOCTYPE html><html> <head> <title> 图书录入数据处理 - 藏书 </title> <meta charset="utf-8"> <link rel="stylesheet" href="add.css"> </head> <body> <div id="header"> <h2 id="核准预览数据"> 核准预览数据 </h2> </div> <div id="container"> <?php /*载入预定义页面*/ include 'definevar.php'; /*全局变量*/ include 'isbn10to13.php'; /*ISBN-10与ISBN-13转换*/ include 'code2loc.php'; include 'code2lang.php'; include 'code2clssys.php'; include 'code2punit.php'; /*代码??信息转换函数组*/ echo 'ISBN-13 国际标准书号:' . $isbn . '<br />'; echo 'CIP 图书在版编目:' . $cip . '</p>' . '<p>正书名:' . $title . '<br />副书名:' . $subtitle . '<br />丛书名:' . $series . '</p>'; $creator1loc = code2loc($creator_loc_id1); echo '<p>作者1:[' . $creator1loc . ']' . $creator_1 . '<br />'; $creator2loc = code2loc($creator_loc_id2); echo '作者2:[' . $creator2loc . ']' . $creator_2 . '</p>'; $publoc = code2loc($publoc_id); echo '<p>由' . $publoc . '的' . $publisher . '出版<br />'; $language = code2lang($lang_id); echo '此' . $language . '发行版本为' . $edit_date . '第' . $edit_no . '版 ' . $version_date . '第' . $version_no . '次印刷</p>'; echo '<p>关键词组1:' . $subj_key_1 . '?' . $subj_key_2 . '?' . $subj_key_3 . '<br />'; $clssys1 = code2clssys($clssys_id_1); echo '关键词组2:' . $subj_key_4 . '?' . $subj_key_5 . '?' . $subj_key_6 . '<br />'; $clssys1 = code2clssys($clssys_id_1); echo $clssys1 . '分类号:' . $class_no_1 . '<br />'; $clssys2 = code2clssys($clssys_id_2); echo $clssys2 . '分类号:' . $class_no_2 . '</p>'; $priceunit = code2punit($punit_id); echo '<p>价格 ' . $price . $priceunit . ' · 藏本数量 ' . $amount . ' · 相关图书ISBN ' . $rlt_isbn . '</p>'; echo '<p>备注信息' . $noteinfo . '</p>'; echo '<h3 id="数据库写入信息">数据库写入信息</h3>'; include 'insert.php'; /*载入写入数据库模块*/ ?> <object type='image/svg+xml' data='bcgen/getbc.php?code=<?php echo $isbn; ?>'></object><br /> <ul> <li><a href="http://book.douban.com/isbn/<?php echo $isbn; ?>/">《<?php echo $title ?>》在豆瓣上的页面</a></li> <li><a href="http://www.amazon.cn/s/field-keywords=<?php echo $isbn; ?>">《<?php echo $title ?>》在亚马逊(中国网站)上的页面</a></li> </ul> </div> <div id="bottom" name="bottom"> <a href="insert.php"><button>确认添加</button></a> <input type="button" value="后退" onclick="javascript:history.back(1)" /> <p id="contact">Developed by SJHSTONE in 2014.</p> </div> </body></html>
数据库连接模块(dbconnect.php)
<?php $dbc = mysqli_connect('localhost', 'mylibr', 'v3rubaGbdfSSTz88', 'libr') or die('无法链接到MySQL数据库'); mysqli_set_charset($dbc,'utf8');
数据写入模块(insert.php)
<?php /*初始连接数据库,连接变量$dbc*/ include 'dbconnect.php'; /*开始写入请求*/ $query1 = "INSERT INTO libr_metacode (meta_isbn, meta_cip) VALUES ('$isbn', '$cip')"; $result = mysqli_query($dbc,$query1) or die('无法写入数据块1'); $query2 = "INSERT INTO libr_title (meta_isbn, title, subtitle, series) VALUES ('$isbn', '$title', '$subtitle', $'series')"; $result = mysqli_query($dbc,$query2) or die('无法写入数据块2'); $query3 = "INSERT INTO libr_author (meta_isbn, creator, creator_id, creatorloc_id) VALUES ('$isbn', '$creator_1', '$creator_loc_id1')"; $result = mysqli_query($dbc,$query3) or die('无法写入数据块3'); /*作者2是否为空*/ if (!empty($creator_2)) { $query4 = "INSERT INTO libr_author (meta_isbn, creator, creator_id, creatorloc_id) VALUES ('$isbn', '$creator_2', '$creator_loc_id2')"; $result = mysqli_query($dbc,$query4) or die('无法写入数据块4'); } else { echo '无写入的作者2信息,不写入数据块4'; } mysqli_close($dbc);
所有从$POST_[]全局变量引用的值都能在echo时正确显示,
能够正常连接并写入libr_metacode表中的13位ISBN、10位CIP数据,
但是无法写入接下来其他表中的数据。
先期涉及的三个表结构:
libr_metacode->meta_isbn char(13) 主键->meta_cip int(10)libr_title->meta_isbn char(13) 主键->title varchar(70)->subtitle varchar(50)->series varchar(30)libr_author (一对多)->rec_id int(5) 自动编号主键->creator varchar(30)->creatorloc_id int(3)
有兴趣的高手麻烦可以到 http://sjhstone.name/book/sandbox.rar看看源码提提建议,密码forcsdn(运行环境为本地Windows上的WampServer)
回复讨论(解决方案)
VALUES ('$isbn', '$cip')";
全都加转义
addslashes($isbn)
或者
mysql_real_escape_string($isbn)
把形如
or die('无法写入数据块1');
的改为形如
or die('无法写入数据块1' . mysqli_error($dbc));
的,就可知道问题在哪里了
VALUES ('$isbn', '$cip')";
全都加转义
addslashes($isbn)
或者
mysql_real_escape_string($isbn)
都是不需要转义的字符,而且只是在本地测试,暂时还用不着防注入……
不过谢啦!
把形如
or die('无法写入数据块1');
的改为形如
or die('无法写入数据块1' . mysqli_error($dbc));
的,就可知道问题在哪里了
这个纠错功能之前没看到过呢
顺带问一下哪里有参考性质的命令大全呢
一切都在 PHP手册 之中

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment