search
Homephp教程php手册如何在十天内学会php之第六天

学习目的:学会添加删除修改数据

mysql_query($exec);

单这个语句就可以执行所有的操作了,不同的就是$exec这个sql语句

添加:$exec="insert into tablename (item1,item2) values ('".$_POST['item1']."',".$_POST['item1'].")";

删除:$exec="delete from tablename where...";

修改:$exec="update tablename set item1='".$_POST['item1']."' where ...";

说到这里就要说一下表单和php变量传递,如果表单中的一个 
表单以POST提交的,那么处理表单文件就可以用$_POST['item1']得到变量值,同样以GET提交的就是$_GET['item1']

是不是很简单?但是通常$exec会有问题,因为可能您的SQL语句会很长,您会遗漏.连接符,或者'来包围字符型字段。

我们可以注释mysql_query($exec);语句用echo $exec;代替来输出$exec以检查正确性。如果您还不能察觉$exec有什么错误的话,可以复制这个sql语句到phpmyadmin中执行,看看它的出错信息。还有需要注意的是,我们不要使用一些敏感的字符串作为字段名字,否则很可能会出现问题,比如说date什么的。变量的命名,字段的命名遵循一点规律有的时候对自己是一种好处,初学者并不可忽视其重要性。

今天就说到这里,明天继续说SESSION。



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

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),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor