Php Can';t使用数据库名称:拒绝用户访问
我正试图建立一个联系形式,并连接到数据库和错误 一直告诉我我无法访问数据库中的表 我已经挣扎了将近7个小时,我真的很累 有人帮忙吗Php Can';t使用数据库名称:拒绝用户访问,php,mysql,html,forms,Php,Mysql,Html,Forms,我正试图建立一个联系形式,并连接到数据库和错误 一直告诉我我无法访问数据库中的表 我已经挣扎了将近7个小时,我真的很累 有人帮忙吗 试试这个 <?php $DB_NAME = "form";//Database name $DB_USER = "root"; $DB_PASSWORD = ""; $DB_HOST = "localhost"; $link = mysql_connect($DB_HOST,$DB_USER,$DB_PASSWORD,$DB_NAME); if (!$
试试这个
<?php
$DB_NAME = "form";//Database name
$DB_USER = "root";
$DB_PASSWORD = "";
$DB_HOST = "localhost";
$link = mysql_connect($DB_HOST,$DB_USER,$DB_PASSWORD,$DB_NAME);
if (!$link){
die("could not connect:" . mysql_error());
};
$db_selected = mysql_select_db($DB_NAME,$link);
if(!$db_selected) {
die("Can\'t use " . $DB_NAME . ' : ' . mysql_error());
};
if (isset($_POST["user_name"])) {
$value = $_POST["user_name"]; // required
$value2 = $_POST["user_eamil"];// required
$value3 = $_POST["subject"];
$value4 = $_POST["text_massege"];// required
//Please use table name here
$sql = "INSERT INTO form (user_name , user_eamil , subject , text_massege) VALUES ('$value','$value2','$value3','$value4')";
if (!mysql_query($sql)){
die("Error: " . mysql_error());
};
// Build the email (replace the address in the $to section with your own)
$email_from = $value2;//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $value.\n".
"Here is the message:\n $value4".
$to = "mail";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $value2 \r\n";
if (!preg_match("/^[a-zA-Z ]*$/",$value)) {
$nameErr = "Only letters and white space allowed";
}
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
mysql_close();
}
?>
<form method="post">
<input type="text" name="user_name" >
<input type="text" name="user_eamil" >
<input type="text" name="subject" >
<input type="text" name="text_massege" >
<input type="submit" value="submit" >
</form>
first notes似乎为db:form的数据库根设置了密码,如果没有,则似乎是在mysql\u select\u db()语句中重新选择数据库。是否确定数据库名为form
,表名为form
?否则这只是一个数据库权限问题,而您没有访问此数据库的权限。我建议您使用mysqli
,因为mysql
不受欢迎。您能解释一下您所做的哪些更改使您相信这会起作用吗?我的伙计,您就是其中之一,问题是我使用的是表的名称,而不是数据库的名称。我不认为答案与问题相关,这是无法连接到数据库的实际问题。但答案是可以接受的。。。想知道怎么做???