无法在xampp上连接数据库

时间:2014-08-08 16:14:10

标签: php mysql

我想尝试使用xampp server开发简单的网页。这是我的html编码

<html>
<body>

<form action="registration2.php" method="post">
id: <input type="text" name="id">
pass: <input type="text" name="pass">
Email: <input type="text" name="email">
<input type="submit">
</form>

</body>
</html> 

这是我的php编码连接到服务器并从html form.my数据库名称接收信息是项目,我的表名是registration.attributes在我的表上是reg_id,reg_pass,reg_email。

  <?php

 //the example of inserting data with variable from HTML form
 mysql_connect("localhost","user_name","password");//database connection
 mysql_select_db("project");

 // Get values from form 
 $id = $_POST['id'];
 $pass = $_POST['pass'];
 $email = $_POST['email'];

  //inserting data order
 $order = "INSERT INTO registration
   (reg_id, reg_pass,reg_email)
  VALUES
   ('$id','$pass','$email')";

 //declare in the order variable
 $result = mysql_query($order); //order executes
 if($result)
{
 echo("
Input data is succeed");
}
 else
{
 echo("
 Input data is fail");
}

?>

我收到了错误。我无法连接到mysql。结果没有显示出来。有人告诉我哪里错了?我的英语不好。

1 个答案:

答案 0 :(得分:0)

尝试添加

$con=mysql_connect("localhost","user_name","password")or die('could not connect'.mysql_error()); //database connection
 mysql_select_db("project",$con);

//all other lines
$order = "INSERT INTO registration
(reg_id, reg_pass,reg_email)
VALUES
('$id','$pass','$email')";

//declare in the order variable
$result = mysql_query($order);
if(!$result) {
die();}