Head First PHP&MySQL笔记(1)
2014-06-10 21:09
381 查看
2014年6月10日
20:22
此处仅将HF PHP&MySQL上的主要代码做注释和笔记(虽然一步步来很精彩 不过对于笔记来说~)。
数据库连接与插入数据:
20:22
此处仅将HF PHP&MySQL上的主要代码做注释和笔记(虽然一步步来很精彩 不过对于笔记来说~)。
数据库连接与插入数据:
1 <?php 2 $first_name = $_POST['firstname']; 3 $last_name = $_POST['lastname']; 4 $when_it_happened = $_POST['whenithappened']; 5 $how_long = $_POST['howlong']; 6 $how_many = $_POST['howmany']; 7 $alien_description = $_POST['aliendescription']; 8 $what_they_did = $_POST['whattheydid']; 9 $fang_spotted = $_POST['fangspotted']; 10 $email = $_POST['email']; 11 $other = $_POST['other']; 12 13 $dbc = mysqli_connect('data.aliensabductedme.com', 'owen', 'aliensrool', 'aliendatabase')//此处用来连接数据库 格式:域名或者ip 用户名 密码 选用的数据库 14 or die('Error connecting to MySQL server.');//连接失败的反馈 15 16 $query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " . 17 "how_many, alien_description, what_they_did, fang_spotted, other, email) " . 18 "VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " . 19 "'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')";//MySQL的插入语句 对应的column插入对应的值 20 21 $result = mysqli_query($dbc, $query)//执行query语句 22 or die('Error querying database.'); 23 24 mysqli_close($dbc);//要有访问完数据库就关闭的良好习惯 数据库的并发访问有限 25 26 echo 'Thanks for submitting the form.<br />'; 27 echo 'You were abducted ' . $when_it_happened; 28 echo ' and were gone for ' . $how_long . '<br />'; 29 echo 'Number of aliens: ' . $how_many . '<br />'; 30 echo 'Describe them: ' . $alien_description . '<br />'; 31 echo 'The aliens did this: ' . $what_they_did . '<br />'; 32 echo 'Was Fang there? ' . $fang_spotted . '<br />'; 33 echo 'Other comments: ' . $other . '<br />'; 34 echo 'Your email address is ' . $email; 35 ?> |
相关文章推荐
- Head First PHP&MySQL 学习笔记(二) —— 创建和填充数据库
- Head First PHP&MySQL学习笔记(一)
- Head First PHP&MySQL 学习笔记(三,四) —— 现实的实际应用
- Head First PHP &MySQL学习笔记
- Head First PHP&MySQL 学习笔记(一)
- Head First PHP&MySQL笔记(3)
- Head First PHP&MySQL笔记(2)
- head first PHP$MySQL 笔记
- Head First PHP &MySQL学习笔记
- Head First PHP&MySQL学习笔记(五)
- Head First PHP&MySQL学习笔记(六)
- Head first PHP&MySQL 学习笔记(一)
- Head First PHP&MySQL学习笔记(四)
- Head First PHP&MySQL学习笔记(三)
- Head First PHP&MySQL 学习笔记(二) —— Connect MySQL
- Head First PHP&MySQL学习笔记(二)
- Head First Mysql笔记
- [head first php&mysql]读书笔记-基本的安全信息(第五章)
- Head First PHP & MySQL.pdf
- HeadFirst PHP&MySQL 重点知识点记录(一)