我有一个数据库运行在我的服务器与phpmyadmin,但我无法连接它。这里是一个例子:无法连接到数据库在php
$user_name = "xxxxx";
$password = "xxxxx";
$database = "xxxxx";
$host = "db.xxxx.nl";
$db_handle = mysql_connect($host, $user_name, $password);
$db_found = mysql_select_db($database);
但这似乎并不奏效。如果我尝试在表格中插入一些值,它仍然是空的。
$sql = "INSERT INTO tbl_forum
(
title,
name,
content,
lastname,
post_image
)
VALUES
(
'{$_POST['contactsubject']}',
'{$_POST['contactname']}',
'{$_POST['contactmessage']}',
'{$_POST['contactlastname']}',
'{$_FILES["contactBrowse"]["name"]}'
)";
我做错了什么?
把'或者死(mysql_error());'在你的查询结束。它告诉你什么? – 2014-10-01 10:42:24
此外,如果你有最新的PHP,然后使用mysqli_ *。因为mysql_ *现在已被弃用。 – 2014-10-01 10:43:55
你是否真的从'$ sql'字符串运行查询? 'mysql_'也是过时的。使用更现代化的教程搜索已准备好的语句 – andrew 2014-10-01 10:44:43