Php 无法连接xampp上的数据库
我想尝试使用xampp服务器开发简单的网页。这是我的html代码Php 无法连接xampp上的数据库,php,mysql,Php,Mysql,我想尝试使用xampp服务器开发简单的网页。这是我的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"> <in
<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表单接收信息。我的数据库名为project,表名为registration。表上的属性为reg\u id、reg\u pass、reg\u 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");
}
?>
尝试添加
$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();}
1) 添加错误处理:mysql\u connect(…)或die(mysql\u error())
。2) 停止使用此代码并了解,3)停止使用过时/不推荐使用的mysql_*()函数。至于你的问题:你在xammp中同时启动了apache和mysql吗?我已经在xamppstill上启动了apache和mysql。我无法连接到我的数据库。我无法连接到我的数据库。此语句“Input data is Success”);}否则{echo(“Input data is fail”);}不会显示。