【发布时间】:2012-02-27 02:33:46
【问题描述】:
我正在尝试创建一个用于注册用户并将他们的信息存储在 MySQL 表中的 php 表单。这是 PHP 代码和 MySQL 表之后的错误。
警告:mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /hsphere/local/home/khalidalomar/khalidalomar.com/talent/第 22 行的 added.php 警告:mysql_query():无法在第 22 行的 /hsphere/local/home/khalidalomar/khalidalomar.com/talent/added.php 中建立到服务器的链接 无效查询:无法连接通过套接字'/var/lib/mysql/mysql.sock'到本地MySQL服务器(2)
这是我的 PHP 代码
include("connect.php");
// Talent table
$t_username = strip_tags(substr($_POST['t_username'],0,32));
$t_password = strip_tags(substr($_POST['t_password'],0,32));
$t_fname = strip_tags(substr($_POST['t_fname'],0,32));
$t_lname = strip_tags(substr($_POST['t_lname'],0,32));
$t_cname = strip_tags(substr($_POST['t_cname'],0,32));
$t_phone = strip_tags(substr($_POST['t_phone'],0,32));
$t_description = strip_tags(substr($_POST['t_description'],0,32));
$t_tags = strip_tags(substr($_POST['t_tags'],0,32));
$results = mysql_query("INSERT INTO talents (id, t_username, t_password, t_fname, t_lname, t_cname, t_phone, t_description, t_tags, t_approved, t_dateofreg)
VALUES ('', '$t_username', '$t_password', '$t_fname', '$t_lname', '$t_cname', '$t_phone', '$t_description', '$t_tags', 'N', NOW() )"); // store date by NOW() // date int(8)
if($results) { echo "Successfully Added"; } else { die('Invalid query: '.mysql_error()); }
?>
如果您需要我可以提供的 SQL 查询。
【问题讨论】:
-
您也应该在
connect.php中提供代码,因为这是连接到数据库的问题,而不是查询失败... -
@MichalPlško 它有我的主机名、数据库用户名、密码和数据库名称。你觉得有必要把它的代码贴出来吗?
-
当然不要暴露密码 :)
xxx在发布之前将它们暴露出来......您在此处发布的代码中没有对数据库的连接调用,所以它在 @987654324 中@ 或者你错过了什么......