8796 sujets

Développement web côté serveur, CMS

Bonjour à tous, je suis nouveau sur alsacréation je tenais avant tout à remercier votre communauté car le contenue de votre site est une vrai mine d'or et pour ça je vous suis très reconnaissant.

Voila depuis quelques semaines j'étudie le langage PHP mySQl avec Dreamweaver CS4. Malgré un ouvrage que je suis à la lettre je suis contraint à faire face à une difficulté assez récurrente pour un novice comme moi. Voila en gros mon problème:
Ayant utilisé l' outils d'édition de DW pour la création d'un formulaire enregistrement voici le code ci-dessous.
Je rencontre la difficulté suivante:
Après avoir fait des essais sur mon serveur local Wamp, j'ai l'apparition de deux erreurs, quand je tente d'envoyer mon formulaire.

voici les erreurs:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\maboutique\TMP86h9uwvfgm.php on line 10

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\wamp\www\maboutique\TMP86h9uwvfgm.php on line 10
Column 'ad_ligne2' cannot be null

La parade que j'ai trouvé pour éviter ces dernières, est la suppression de la ligne 10 de ma page

ligne 10 : $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

Mon formulaire envoie bien les informations à ma table donc au final tout va bien...

Oui mais voila étant de nature curieuse je souhaiterai connaitre le fin mot de l'histoire!
Pourquoi cette ligne me fait apparaitre ces deux erreurs?

je vous remercie par avance pour vos conseils

VOICI MON CODE:



<?php require_once('Connections/Boutique.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  $MM_dupKeyRedirect="signin.php";
  $loginUsername = $_POST['mail'];
  $LoginRS__query = sprintf("SELECT mail FROM shop_client WHERE mail=%s", GetSQLValueString($loginUsername, "text"));
  mysql_select_db($database_Boutique, $Boutique);
  $LoginRS=mysql_query($LoginRS__query, $Boutique) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);

  //if there is a row in the database, the username was found - can not add the requested username
  if($loginFoundUser){
    $MM_qsChar = "?";
    //append the username to the redirect page
    if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
    $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
    header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO shop_client (id, nom, prenom, mdp, mail, telephone, ad_ligne1, ad_cp, ad_ville) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['nom'], "text"),
                       GetSQLValueString($_POST['prenom'], "text"),
                       GetSQLValueString($_POST['mdp'], "text"),
                       GetSQLValueString($_POST['mail'], "text"),
                       GetSQLValueString($_POST['telephone'], "text"),
                       GetSQLValueString($_POST['ad_ligne1'], "text"),
                       GetSQLValueString($_POST['ad_cp'], "text"),
                       GetSQLValueString($_POST['ad_ville'], "text"));

  mysql_select_db($database_Boutique, $Boutique);
  $Result1 = mysql_query($insertSQL, $Boutique) or die(mysql_error());

  $insertGoTo = "valide_inscription.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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>inscription</title>
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->
</script>
</head>
<body>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center"><strong><?php if (isset($_GET['requsername'])) {?>Cette adresse mail est éjà utilisée sur cette boutique. 
Veuillez en utiliser une autre pour créer votre compte. <?php } ?> </strong></td>
  </tr>
</table>



<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1" onsubmit="MM_validateForm('nom','','R','prenom','','R','mdp','','R','mail','','RisEmail','ad_ligne1','','R','ad_cp','','R','ad_ville','','R');return document.MM_returnValue">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nom:</td>
      <td><input name="nom" type="text" id="nom" value="" size="32" maxlength="64" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Prenom:</td>
      <td><input name="prenom" type="text" id="prenom" value="" size="32" maxlength="64" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Mot de passe :</td>
      <td><input name="mdp" type="password" id="mdp" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Mail:</td>
      <td><input name="mail" type="text" id="mail" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Telephone:</td>
      <td><input name="telephone" type="text" value="" size="32" maxlength="10" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Adresse :</td>
      <td><textarea name="ad_ligne1" cols="32" id="ad_ligne1"></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Code postal:</td>
      <td><input name="ad_cp" type="text" id="ad_cp" value="" size="32" maxlength="5" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Ville:</td>
      <td><input name="ad_ville" type="text" id="ad_ville" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="valider votre inscription" /></td>
    </tr>
  </table>
  <input type="hidden" name="id" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>

[/i] 


Modifié par Lavazza (27 Jan 2010 - 00:39)
Hello Lavazza et bienvenue,

tout d'abord et comme indiqué dans les règles du forum ton avatar ne doit pas gêner le confort de lecture du forum... ce qui n'est pas le cas des gifs animés. Merci par avance d'en choisir un moins "distrayant". Smiley cligne

Pour ce qui est de mysql_real_escape_string cette fonction ne doit être utilisée qu'après s'être connecté à la base de données.
Administrateur
Il faut être connecté à MySQL avant d'utiliser la fonction mysql_real_escape_string() - qui interroge le serveur.

Le message d'erreur provient de cela : PHP tente d'établir une connexion par défaut (sans login et mot de passe) ce qui ne passe pas.