我是新手使用xampp,直到一周前我使用托管服务器进行php开发。我有可能是一个新手问题,并希望得到任何建议。
我已经让phpmyadmin工作并创建了一个拥有完全权限的数据库和用户。我将在托管服务器上执行的所有操作。当我尝试使用mysqli连接时,我收到以下错误:
警告:mysqli :: mysqli():( HY000 / 1045):在C:\ xampp \ htdocs \ cromwell \ dbconnect.php上用户“cromwell”@“localhost”(使用密码:YES)拒绝访问2 连接失败:用户'cromwell'@'localhost'拒绝访问(使用密码:是)
使用以下SQL设置用户帐户权限:
REVOKE ALL PRIVILEGES ON *.* FROM 'cromwell'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'cromwell'@'localhost' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
连接脚本如下:
<?
$mysqli = new mysqli("localhost", "cromwell", 'password', "cromwell");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
?>
当我创建用户时,用户和数据库都按照phpmyadmin的设置命名为cromwell。
我认为我在用户设置或我从脚本中寻址数据库时遗漏了一些简单的东西。
感谢您提供任何帮助或建议。
答案 0 :(得分:-1)
Sql connection using PDO Methode:
<?php
/* Database config */
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_database = 'sales';
/* End config */
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_database, $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
答案 1 :(得分:-2)
Sql connection using MySql Methode:
?php
$database="gzone";
$username="root";
$password="";
$conn = mysql_connect("","$username","$password");
if(!$conn)
{
die('<h2>connection can not be established properly :</h2>'. mysql_error());
}
$db=mysql_select_db($database);
if(!$db)
{
die('<h2>fatal error in database</h2>'.mysql_error());
}
?>
///////////////////////////////////////////////////////////////////
LOgin in PhP:
<?php
session_start();
include('conn.php');
$email = $_POST['email'];
$password = $_POST['password'];
$sql = mysql_query("SELECT user_type,email FROM guser WHERE email= '$email' and password='$password'") or die(mysql_error());
if(mysql_num_rows($sql) ==1){
$result = mysql_fetch_assoc($sql);
$user_type= $result['user_type'];
session_start();
if($user_type!='admin'){
$_SESSION['uname'] = $email;
$_SESSION['user_type']= $user_type;
header("location:index.php");
exit();
}
else{
$_SESSION['uname'] = $email;
$_SESSION['user_type'] = $user_type;
header("location: ./admin_data/admin.php");
exit();
}
}else{
header("location:index.php?message=invalid-user");
exit();
}
?>
////////////////////////////////////////////////////
SignUp in Php:
<?php
include_once('conn.php');
$name=$_POST['name'];
$password=$_POST['password'];
$email=$_POST['email'];
$cnic=$_POST['cnic'];
$phoneno=$_POST['phon_no'];
$visacard=$_POST['visa'];
$DOB=$_POST['dob'];
$q="insert into guser(username,password,email,cnic_no,phone_no,visa_card,dob,user_type)values('".$name."','".$password."','".$email."','".$cnic."','".$phoneno."','".$visacard."','".$DOB."','user')";
if(!mysql_query($q,$conn))
{
die('fatal error'.mysql_error());
}
header('location: GAMMING ZONE.COM.php?signup=t');
exit();
?>
//////////////////////////////////////////////////
Java Script Validation is:
<script>
function validlogin(){
var email1_value = document.getElementById("email1").value;
var p1_value = document.getElementById("password").value;
if(!email1_value)
{
alert("Invalid email!");
return false;
}
if(p1_value.length==0)
{
alert("please enter password!");
return false;
}
}
function validation(){
var name_value = document.getElementById("name").value;
var p_value = document.getElementById("password2").value;
var cp_value = document.getElementById("retpassword").value;
var email_value = document.getElementById("email").value;
var cnic_value = document.getElementById("nic").value;
var phone_value = document.getElementById("phone").value;
var visa_value = document.getElementById("visa").value;
var DOB_value = document.getElementById("dob").value;
var reg_nic = /^[1-9]{1}[0-9]{4}\-[0-9]{7}\-[0-9]{1}$/;
var reg_ph = /^03[0-9]{2}\-[0-9]{7}$/;
var reg_visa=/^[1-9]{1}[0-9]{15}$/;
if(name_value.length==0){
alert("Name lenght is not okay!");
return false;
}
//alert(p_value);
if(p_value.length==0)
{
alert("please enter password!");
return false;
}
if(!cp_value)
{
alert("must retype password!");
return false;
}
if(p_value!=cp_value){
alert("Password dose not match!");
return false;
}
if(!email_value)
{
alert("Invalid email!");
return false;
}
if(reg_nic.test(cnic_value)==false){
alert("Invalid Nic!");
return false;
}
if(reg_ph.test(phone_value)==false){
alert("Invalid Mobile no!");
return false;
}
if(reg_visa.test(visa_value)==false){
alert("Invalid visa card number!");
return false;
}
if(!DOB_value){
alert("Invalid date of birth!");
return false;
}
}
function search(){
var search = document.getElementById("sname").value;
if(search.length==0)
{
alert("Search for games...!");
return false;
}
}
</script>
/////////////////////////////////////////////////////////
Query string Back to action page through Get Function:
<?php
session_start();
if(isset($_SESSION['uname']) && isset($_SESSION['user_type']) && $_SESSION['user_type']=='user')
{
echo'<h3 style="color:white">wellcome '.$_SESSION['uname'].' </h3>';
}
if(isset($_GET['signup'])){
echo '<h3 style="color:white">you are successfully signup.</h3>';
}
?>
<div class="main-body-section-left-title"><h2>MANAGE USER'S</h2></div>
<?php
include_once('../conn.php');
$q=mysql_query("select * from guser");
?>
<form action="manage_user.php" method="post" style="margin-left:-150px;">
<table class="table_decoration" border="7px" >
<tr class="row_decoration">
<th style="color:#00ff00;">USER NAME</th>
<th style="color:#00ff00;">EMAIL</th>
<th style="color:#00ff00;">PASSWORD</th>
<th style="color:#00ff00;">CNIC_NO</th>
<th style="color:#00ff00;">PHONE_NO</th>
<th style="color:#00ff00;">VISA CARD NO</th>
<th style="color:#00ff00;">DOB</th>
<th style="color:#00ff00;">USER TYPE</th>
<th style="color:#00ff00;">DELETE</th>
<th style="color:#00ff00;">UPDATE</th>
<th><a href="add_user.php"><p style="color:#00ff00;">ADD</p></a></th>
</tr>
<?php
while($row=mysql_fetch_array($q)){
echo ' <tr class="row_dec">
<td style="color:white">'.$row['username'].'</td>
<td style="color:white">'.$row['email'].'</td>
<td style="color:white">'.$row['password'].'</td>
<td style="color:white">'.$row['cnic_no'].'</td>
<td style="color:white">'.$row['phone_no'].'</td>
<td style="color:white">'.$row['visa_card'].'</td>
<td style="color:white">'.$row['dob'].'</td>
<td style="color:white">'.$row['user_type'].'</td>
<td>
<a href="#?email='.$row['email'].'" onClick="if(window.confirm(\'Are you want to delete this user? \'))
{ window.location =\'delete_user.php?email='.$row['email'].'\'; }">
<p style="color:yellow;">Delete</p></a>
</td>
<td> <a href="update_user.php?email='.$row['email'].'"><p style="color:yellow">Update </p></a></td>
</tr>';
}
?>
</table>
</form>
</div>