Home > Backend Development > PHP Tutorial > 大家帮小弟我看一上这个php写mysql是那里出了有关问题

大家帮小弟我看一上这个php写mysql是那里出了有关问题

WBOY
Release: 2016-06-13 13:00:28
Original
754 people have browsed it

大家帮我看一下这个php写mysql是那里出了问题?
html:

<center> <br />
<form action="addData.php" method="post" target="_blank" ><br />
<p>账号:<input name="u_User" title="text" size="32" maxlength="32" /></p><br />
<p>密码:<input  name="u_pwd" title="text" size="32" maxlength="32"/></p><br />
<input type="submit" value="注册" /><input type="reset" value="清空" /><br />
</form></center>
Copy after login


php:
    <?php   <br />
    /////////////////和mysql建立链接  <br />
    $host = "localhost";$user="root";$pwd="";$DataBaseName="db_appdata";$db_name="appdata";<br />
    $con = mysql_connect($host,$user,$pwd);  <br />
     if (!$con)    <br />
        {    <br />
        die('连接数据库失败: ' . mysql_error());   <br />
        }   <br />
    mysql_select_db($DataBaseName, $con);    //选取数据库  <br />
    ////////////////////向表内插入数据  <br />
    mysql_query("INSERT INTO $db_name (Name, pwd)  <br />
     VALUES (.trim($_POST["u_user"]), .trim($_POST["u_pwd"])");  <br />
     echo "添加成功"; <br />
    //关闭连接  <br />
    mysql_close($con);?>
Copy after login


连接数据库可以成功,怎么就写不进数据呢?
------解决方案--------------------
插入sql有错
而且$_POST["u_User"]

------解决方案--------------------
mysql_query("INSERT INTO $db_name (Name, pwd)  
     VALUES ('".trim($_POST["u_user"])."', '".trim($_POST["u_pwd"])."'");  
------解决方案--------------------

本帖最后由 xuzuning 于 2012-12-02 12:39:58 编辑 1、表单里是 name="u_User" ,提交后要 $_POST['u_User']
  php 的变量是区分大小写的
2、字符串中写入 $_POST["u_User"] 时 $_POST["u_User"] 要用 {} 括起:{$_POST["u_User"]}
  或写作 $_POST[u_User]
  这是 php 的书写规则,必须遵守
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template