Home > Backend Development > PHP Tutorial > php新手 简单留言板有关问题

php新手 简单留言板有关问题

PHP中文网
Release: 2016-06-13 10:42:37
Original
744 people have browsed it

  php新手求助 简单留言板问题
这是源代码

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
   {
   die(&#39;Could not connect: &#39; . mysql_error());
   }
$db_selected = mysql_select_db("test_db", $con);
if (!$db_selected)
   {
   die ("Can\&#39;t use test_db : " . mysql_error());
   }
$sql = "INSERT INTO `test_db`.`form` (`name`, `pass`) VALUES (\&#39;fdgsdfg\&#39;, \&#39;dsfgsdfg\&#39;);";
mysql_query($sql,$con);
?>
Copy after login

似乎能连接到数据库 但是 就是没办法更新到数据库
数据库非常简单字段 类型 整理 属性 空 默认 额外 操作
字段就两个 name 和pass
希望高手快来看看


------解决方案--------------------
"INSERT INTO `test_db`.`form` (`name`, `pass`) VALUES (\'fdgsdfg\', \'dsfgsdfg\');"
首先由于这段字符串在双引号内,所以与单引号不冲突,因此不许要 \ 转义
其次也不需要用分号结尾。因为mysql_query()本身一次只发送一条查询语句给mysql。
修改后的代码:

  • PHP code
  • $sql = "INSERT INTO `test_db`.`form` (`name`, `pass`) VALUES (&#39;fdgsdfg&#39;, &#39;dsfgsdfg&#39;)";mysql_query($sql,$con) or exit( mysql_error() ); // 这是重点,它将告诉你为什么出错
    Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template