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

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

WBOY
WBOYOriginal
2016-06-13 13:18:26975browse

php新手求助 简单留言板问题
这是源代码
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db_selected = mysql_select_db("test_db", $con);
if (!$db_selected)
  {
  die ("Can\'t use test_db : " . mysql_error());
  }
$sql = "INSERT INTO `test_db`.`form` (`name`, `pass`) VALUES (\'fdgsdfg\', \'dsfgsdfg\');";
mysql_query($sql,$con);
?>
似乎能连接到数据库 但是 就是没办法更新到数据库
数据库非常简单字段 类型 整理 属性 空 默认 额外 操作 
字段就两个 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 ('fdgsdfg', 'dsfgsdfg')";
mysql_query($sql,$con) or exit( mysql_error() ); // 这是重点,它将告诉你为什么出错 <div class="clear">
                 
              
              
        
            </div>
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