Warning: real_escape_string
ciranox
Messages postés
436
Statut
Membre
-
ciranox Messages postés 436 Statut Membre -
ciranox Messages postés 436 Statut Membre -
Bonjour,
J'ai un problème avec mon code php:
voici les erreurs :
warning:mysqli:mysqli()[mysqli.mysqli]:(2800/1045): Access denied for user 'USERNAME'@'localhost' (using password:YES) in C:\Program Files\xampp\htdocs\autocomplete/rpc.php on line 5
warning:mysqli:mysqli:real_escape_string()[mysqli.real-escape-string]:couldn't fetch musqli in C:\Program Files\xampp\htdocs\autocomplete/rpc.php on line 13
J'ai cherché sur google pour voir la fonction real_escape_string , est obsolète .
Je ne comprend pas d'où peut venir le problème .
voici le code php:
<?php
// PHP5 Implementation - uses MySQLi.
// mysqli('localhost', 'aimeric', 'roffbmw94', 'countries');
$db = new mysqli('localhost', 'USERNAME' ,'PASSWORD', 'DATABASE');
if(!$db) {
// Show error if we cannot connect.
echo 'ERROR: Could not connect to the database.';
} else {
// Is there a posted query string?
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
// Run the query: We use LIKE '$queryString%'
// The percentage sign is a wild-card, in my example of countries it works like this...
// $queryString = 'Uni';
// Returned data = 'United States, United Kindom';
// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10
$query = $db->query("SELECT your_column FROM your_db_table WHERE your_column LIKE '$queryString%' LIMIT 10");
if($query) {
// While there are results loop through them - fetching an Object (i like PHP5 btw!).
while ($result = $query ->fetch_object()) {
// Format the results, im using <li> for the list, you can change it.
// The onClick function fills the textbox with the result.
// YOU MUST CHANGE: $result->value to $result->your_colum
echo '<li onClick="fill(\''.$result->value.'\');">'.$result->value.'</li>';
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
}
?>
Merci d'avance.
J'ai un problème avec mon code php:
voici les erreurs :
warning:mysqli:mysqli()[mysqli.mysqli]:(2800/1045): Access denied for user 'USERNAME'@'localhost' (using password:YES) in C:\Program Files\xampp\htdocs\autocomplete/rpc.php on line 5
warning:mysqli:mysqli:real_escape_string()[mysqli.real-escape-string]:couldn't fetch musqli in C:\Program Files\xampp\htdocs\autocomplete/rpc.php on line 13
J'ai cherché sur google pour voir la fonction real_escape_string , est obsolète .
Je ne comprend pas d'où peut venir le problème .
voici le code php:
<?php
// PHP5 Implementation - uses MySQLi.
// mysqli('localhost', 'aimeric', 'roffbmw94', 'countries');
$db = new mysqli('localhost', 'USERNAME' ,'PASSWORD', 'DATABASE');
if(!$db) {
// Show error if we cannot connect.
echo 'ERROR: Could not connect to the database.';
} else {
// Is there a posted query string?
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
// Run the query: We use LIKE '$queryString%'
// The percentage sign is a wild-card, in my example of countries it works like this...
// $queryString = 'Uni';
// Returned data = 'United States, United Kindom';
// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10
$query = $db->query("SELECT your_column FROM your_db_table WHERE your_column LIKE '$queryString%' LIMIT 10");
if($query) {
// While there are results loop through them - fetching an Object (i like PHP5 btw!).
while ($result = $query ->fetch_object()) {
// Format the results, im using <li> for the list, you can change it.
// The onClick function fills the textbox with the result.
// YOU MUST CHANGE: $result->value to $result->your_colum
echo '<li onClick="fill(\''.$result->value.'\');">'.$result->value.'</li>';
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
}
?>
Merci d'avance.
A voir également:
- Warning: real_escape_string
- Warning zone telechargement - Accueil - Outils
- Symbole warning word ✓ - Forum Loisirs / Divertissements
- Warning battery is low ✓ - Forum Matériel & Système
- Cpu fan fail warning control - Forum BIOS
- Quota warning free - Guide
2 réponses
bonjour,
ton probleme viens de ta connection, tu n'as pas le bon mot de passe / nom d'utilisateur :
warning:mysqli:mysqli()[mysqli.mysqli]:(2800/1045): Access denied for user 'USERNAME'@'localhost' (using password:YES) in C:\Program Files\xampp\htdocs\autocomplete/rpc.php on line 5
access denied ... = acces refusé
enfait les "//" dans ton code permetent de mettre des lignes en commentaires (elles ne seront pas executées)
donc
// mysqli('localhost', 'aimeric', 'roffbmw94', 'countries');
ne fais rien,
c'est ici que tu dois mettre ton mot de passe etc... :
$db = new mysqli('localhost', 'USERNAME' ,'PASSWORD', 'DATABASE');
ton probleme viens de ta connection, tu n'as pas le bon mot de passe / nom d'utilisateur :
warning:mysqli:mysqli()[mysqli.mysqli]:(2800/1045): Access denied for user 'USERNAME'@'localhost' (using password:YES) in C:\Program Files\xampp\htdocs\autocomplete/rpc.php on line 5
access denied ... = acces refusé
enfait les "//" dans ton code permetent de mettre des lignes en commentaires (elles ne seront pas executées)
donc
// mysqli('localhost', 'aimeric', 'roffbmw94', 'countries');
ne fais rien,
c'est ici que tu dois mettre ton mot de passe etc... :
$db = new mysqli('localhost', 'USERNAME' ,'PASSWORD', 'DATABASE');
Merci de ta réponse.
Effectivement il y a plus d'erreurs . En fait c'est un petit moteur de recherche autocomplete qui va chercher dans ma base des mots clefs. Le problème est que quand j'écris dans le champs texte mon d'info bulle m'affiche:
Error : error: there was à problem with the query
Normalement il devrait m'afficher les infos qui se trouve dans la bdd.
Effectivement il y a plus d'erreurs . En fait c'est un petit moteur de recherche autocomplete qui va chercher dans ma base des mots clefs. Le problème est que quand j'écris dans le champs texte mon d'info bulle m'affiche:
Error : error: there was à problem with the query
Normalement il devrait m'afficher les infos qui se trouve dans la bdd.
La colonne sql s'appelle déjà value .
Voici le script qui affiche le champ texte:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Auto Suggest</title>
<script type="text/javascript" src="jquery-1.2.1.pack.js"></script>
<script type="text/javascript">
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
} // lookup
function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
</script>
<style type="text/css">
body {
font-family: Helvetica;
font-size: 11px;
color: #000;
}
h3 {
margin: 0px;
padding: 0px;
}
.suggestionsBox {
position: relative;
left: 30px;
margin: 10px 0px 0px 0px;
width: 200px;
background-color: #212427;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}
.suggestionList {
margin: 0px;
padding: 0px;
}
.suggestionList li {
margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}
.suggestionList li:hover {
background-color: #659CD8;
}
</style>
</head>
<body>
<div>
<form>
<div>
Type your county:
<br />
<input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
</div>
<div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList">
</div>
</div>
</form>
</div>
</body>
</html>
Voici le script qui affiche le champ texte:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Auto Suggest</title>
<script type="text/javascript" src="jquery-1.2.1.pack.js"></script>
<script type="text/javascript">
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
} // lookup
function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
</script>
<style type="text/css">
body {
font-family: Helvetica;
font-size: 11px;
color: #000;
}
h3 {
margin: 0px;
padding: 0px;
}
.suggestionsBox {
position: relative;
left: 30px;
margin: 10px 0px 0px 0px;
width: 200px;
background-color: #212427;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}
.suggestionList {
margin: 0px;
padding: 0px;
}
.suggestionList li {
margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}
.suggestionList li:hover {
background-color: #659CD8;
}
</style>
</head>
<body>
<div>
<form>
<div>
Type your county:
<br />
<input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
</div>
<div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList">
</div>
</div>
</form>
</div>
</body>
</html>
value ne devrais ps etre nul dans ton input puisque c'est ça qui fais tous planté cherche dans la doc du truc que t'as utiliser pour savoir quoi y mettre
rectification : tu dois changer ça :
$query = $db->query("SELECT your_column FROM your_db_table WHERE your_column LIKE '$queryString%' LIMIT 10");
(value est effectivement nul)
rectification : tu dois changer ça :
$query = $db->query("SELECT your_column FROM your_db_table WHERE your_column LIKE '$queryString%' LIMIT 10");
(value est effectivement nul)